extra-1.4.2: Extra functions I use.

Safe Haskell | Safe
Language | Haskell2010

Data.Tuple.Extra

Contents

- Specialised `Arrow` functions
- More pair operations
- Extract from a triple

Description

Extra functions for working with pairs and triples. Some of these functions are available in the Control.Arrow module, but here are available specialised to pairs. Some operations work on triples.

Synopsis

- module Data.Tuple
- first :: (a -> a') -> (a, b) -> (a', b)
- second :: (b -> b') -> (a, b) -> (a, b')
- (***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
- (&&&) :: (a -> b) -> (a -> c) -> a -> (b, c)
- dupe :: a -> (a, a)
- both :: (a -> b) -> (a, a) -> (b, b)
- fst3 :: (a, b, c) -> a
- snd3 :: (a, b, c) -> b
- thd3 :: (a, b, c) -> c

# Documentation

module Data.Tuple

# Specialised `Arrow` functions

first :: (a -> a') -> (a, b) -> (a', b)

Update the first component of a pair.

    first succ (1,"test") == (2,"test")

second :: (b -> b') -> (a, b) -> (a, b')

Update the second component of a pair.

    second reverse (1,"test") == (1,"tset")

(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') infixr 3

Given two functions, apply one to the first component and one to the second. A specialised version of `***`.

    (succ *** reverse) (1,"test") == (2,"tset")

(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c) infixr 3

Given two functions, apply both to a single argument to form a pair. A specialised version of `&&&`.

    (succ &&& pred) 1 == (2,0)

# More pair operations

dupe :: a -> (a, a)

Duplicate a single value into a pair.

    dupe 12 == (12, 12)

both :: (a -> b) -> (a, a) -> (b, b)

Apply a single function to both components of a pair.

    both succ (1,2) == (2,3)

# Extract from a triple

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

Extract the `fst` of a triple.

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

Extract the `snd` of a triple.

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

Extract the final element of a triple.