packages feed

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

{- |
Module      : Antelude.Tuple.Trio
Description : Contains some functions for a three-member Tuple (a Trio).
Maintainer  : dneavesdev@pm.me
-}
module Antelude.Tuple.Trio
    ( Trio
    , curry
    , cycleCCW
    , cycleCW
    , first
    , mapFirst
    , mapSecond
    , mapThird
    , pack
    , reverse
    , second
    , third
    , uncurry
    ) where

import safe           Antelude.Internal.TypesClasses ( Trio )


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


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


-- | Get the third item of a 'Trio' Tuple
third :: Trio a b c -> c
third (_, _, c) = c


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


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


-- | Apply a function to the third item of a 'Trio' Tuple
mapThird :: (c -> z) -> Trio a b c -> Trio a b z
mapThird fn (a, b, c) = (a, b, fn c)


{- |
   Rotates the item of a 'Trio' Tuple, moving to the right.
   The last item loops back to the first
-}
cycleCW :: Trio a b c -> Trio c a b
cycleCW (a, b, c) = (c, a, b)


{- |
   Rotates the item of a 'Trio' Tuple, moving to the left.
   The first item loops back to the last
-}
cycleCCW :: Trio a b c -> Trio b c a
cycleCCW (a, b, c) = (b, c, a)


-- | Flip the 'Trio' Tuple around, so the first becomes the last and vice versa.
reverse :: Trio a b c -> Trio c b a
reverse (a, b, c) = (c, b, a)


-- | Pack all three arguments into a 'Trio' Tuple
pack :: a -> b -> c -> Trio a b c
pack a b c = (a, b, c)

-- | convert an uncurried function into a curried function
curry :: ((a, b, c) -> d) -> a -> b -> c -> d
curry fn a b c = fn (a, b, c)

-- | convert a curried function to a function on a 'Trio'
uncurry :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry fn (a, b, c) = fn a b c