packages feed

antelude-0.1.0: src/Antelude/Tuple/Pair.hs

{- |
Module      : Antelude.Tuple.Pair
Description : Contains some functions for a two-member Tuple (a Pair).
Maintainer  : dneavesdev@pm.me
-}
module Antelude.Tuple.Pair
    ( Pair
    , curry
    , first
    , mapFirst
    , mapSecond
    , pack
    , second
    , swap
    , uncurry
    ) where

import safe           Antelude.Internal.TypesClasses ( Pair )

import safe           Data.Tuple                     ( curry, uncurry )


-- | Get the first item of a 'Pair' Tuple
first :: Pair a b -> a
first (a, _) = a


-- | Get the second item of a 'Pair' Tuple
second :: Pair a b -> b
second (_, b) = b


-- | Apply a function to the first item of a 'Pair' Tuple
mapFirst :: (a -> z) -> Pair a b -> Pair z b
mapFirst fn (a, b) = (fn a, b)


-- | Apply a function to the second item of a 'Pair' Tuple
mapSecond :: (b -> z) -> Pair a b -> Pair a z
mapSecond fn (a, b) = (a, fn b)


-- | Swap the items in a 'Pair' Tuple
swap :: Pair a b -> Pair b a
swap (a, b) = (b, a)


-- | Pack both arguments into a 'Pair' Tuple
pack :: a -> b -> Pair a b
pack a b = (a, b)