packages feed

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

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

module Papa.Lens.Data.Tuple (
  fst,
  snd,
) where

import Control.Lens (Field1, Field2, (^.), _1, _2)

-- | Extract the first component of a pair.
--
-- >>> fst (1, 2)
-- 1
-- >>> fst ('a', "hello")
-- 'a'
{-# INLINE fst #-}
{-# SPECIALIZE fst ::
  (a, b) ->
  a
  #-}
fst ::
  (Field1 s s b b) =>
  s ->
  b
fst =
  (^. _1)

-- | Extract the second component of a pair.
--
-- >>> snd (1, 2)
-- 2
-- >>> snd ('a', "hello")
-- "hello"
{-# INLINE snd #-}
{-# SPECIALIZE snd ::
  (a, b) ->
  b
  #-}
snd ::
  (Field2 s s b b) =>
  s ->
  b
snd =
  (^. _2)