utility-ht-0.0.15: Various small helper functions for Lists, Maybes, Tuples, Functions

Safe HaskellSafe
LanguageHaskell98

Data.Tuple.HT

Contents

Synopsis
  • mapPair :: (a -> c, b -> d) -> (a, b) -> (c, d)
  • mapFst :: (a -> c) -> (a, b) -> (c, b)
  • mapSnd :: (b -> c) -> (a, b) -> (a, c)
  • swap :: (a, b) -> (b, a)
  • sortPair :: Ord a => (a, a) -> (a, a)
  • forcePair :: (a, b) -> (a, b)
  • double :: a -> (a, a)
  • fst3 :: (a, b, c) -> a
  • snd3 :: (a, b, c) -> b
  • thd3 :: (a, b, c) -> c
  • mapTriple :: (a -> d, b -> e, c -> f) -> (a, b, c) -> (d, e, f)
  • mapFst3 :: (a -> d) -> (a, b, c) -> (d, b, c)
  • mapSnd3 :: (b -> d) -> (a, b, c) -> (a, d, c)
  • mapThd3 :: (c -> d) -> (a, b, c) -> (a, b, d)
  • curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
  • uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
  • triple :: a -> (a, a, a)

Pair

mapPair :: (a -> c, b -> d) -> (a, b) -> (c, d) Source #

Cf. '(Control.Arrow.***)'.

Apply two functions on corresponding values in a pair, where the pattern match on the pair constructor is lazy. This is crucial in recursions such as the one of partition. One the other hand there are applications where strict application is crucial, e.g. mapSnd f ab where the left pair member is a large lazy list. With the lazy mapSnd we make the application of f depend on the whole pair ab. See Data.Tuple.Example for two examples where one variant is definitely better than the other one.

mapFst :: (a -> c) -> (a, b) -> (c, b) Source #

mapSnd :: (b -> c) -> (a, b) -> (a, c) Source #

swap :: (a, b) -> (b, a) Source #

sortPair :: Ord a => (a, a) -> (a, a) Source #

This is convenient for quick hacks but I suggest that you better define a type for an ordered pair for your application at hand. This way, you can clearly see from the type that a pair is ordered.

forcePair :: (a, b) -> (a, b) Source #

double :: a -> (a, a) Source #

Known as dup in the Arrow literature.

Triple

fst3 :: (a, b, c) -> a Source #

snd3 :: (a, b, c) -> b Source #

thd3 :: (a, b, c) -> c Source #

mapTriple :: (a -> d, b -> e, c -> f) -> (a, b, c) -> (d, e, f) Source #

mapFst3 :: (a -> d) -> (a, b, c) -> (d, b, c) Source #

mapSnd3 :: (b -> d) -> (a, b, c) -> (a, d, c) Source #

mapThd3 :: (c -> d) -> (a, b, c) -> (a, b, d) Source #

curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d Source #

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d Source #

triple :: a -> (a, a, a) Source #