packages feed

papa-0.7.0: src/Papa/Lens/Data/Tuple.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

-- | The first and second components of any tuple.
module Papa.Lens.Data.Tuple (
  fst,
  snd,
) where

import Control.Lens (Field1, Field2, _1, _2)
import Papa.Lens.Optic (the)

-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa
-- >>> import Hedgehog
-- >>> import qualified Hedgehog.Gen as Gen
-- >>> import qualified Hedgehog.Range as Range
-- >>> let genInt = Gen.int (Range.linear (-100) 100)

-- | The first component of any tuple ('Field1').
--
-- ==== __Examples__
--
-- >>> fst (1 :: Int, 'a')
-- 1
--
-- >>> fst ('a', True, ())
-- 'a'
--
-- >>> check $ withTests 100 $ property $ do a <- forAll genInt; b <- forAll Gen.alpha; fst (a, b) === a
-- ...passed 100 tests.
-- True
--
-- @since 0.4.0
fst :: (Field1 s s b b) => s -> b
fst =
  the _1
{-# INLINE fst #-}

-- | The second component of any tuple ('Field2').
--
-- ==== __Examples__
--
-- >>> snd (1 :: Int, 'a')
-- 'a'
--
-- >>> snd ('a', True, ())
-- True
--
-- >>> check $ withTests 100 $ property $ do a <- forAll genInt; b <- forAll Gen.alpha; snd (a, b) === b
-- ...passed 100 tests.
-- True
--
-- @since 0.4.0
snd :: (Field2 s s b b) => s -> b
snd =
  the _2
{-# INLINE snd #-}