Std\Tuple
Operations on 2-tuples (pairs).
Tuples are the built-in product type (a, b). This module provides
accessors, transformers, and conversion functions.
Functions
Section titled “Functions”fst : (a, b) -> Int
Section titled “fst : (a, b) -> Int”Returns the first element of a pair.
fst (1, 2) # => 1snd : (a, b) -> Int
Section titled “snd : (a, b) -> Int”Returns the second element of a pair.
snd (1, 2) # => 2swap : (a, b) -> (c, d)
Section titled “swap : (a, b) -> (c, d)”Swaps the elements of a pair.
swap (1, 2) # => (2, 1)mapBoth : (a -> b) -> (c -> d) -> (e, f) -> (g, h)
Section titled “mapBoth : (a -> b) -> (c -> d) -> (e, f) -> (g, h)”Applies two functions to the respective elements.
mapBoth (\x -> x + 1) (\x -> x * 2) (3, 5) # => (4, 10)mapFst : (a -> b) -> (c, d) -> (e, f)
Section titled “mapFst : (a -> b) -> (c, d) -> (e, f)”Transforms the first element, keeping the second unchanged.
mapFst (\x -> x * 10) (3, 5) # => (30, 5)mapSnd : (a -> b) -> (c, d) -> (e, f)
Section titled “mapSnd : (a -> b) -> (c, d) -> (e, f)”Transforms the second element, keeping the first unchanged.
mapSnd (\x -> x * 10) (3, 5) # => (3, 50)toList : (a, b) -> [c]
Section titled “toList : (a, b) -> [c]”Converts a pair to a two-element sequence.
toList (1, 2) # => [1, 2]curry : (a -> b) -> Int -> Int -> (c, d)
Section titled “curry : (a -> b) -> Int -> Int -> (c, d)”Converts a function taking a pair into one taking two arguments.
let add = \(a, b) -> a + b in curry add 3 4 # => 7uncurry : (a -> b) -> (c, d) -> Int
Section titled “uncurry : (a -> b) -> (c, d) -> Int”Converts a function taking two arguments into one taking a pair.
let add = \a b -> a + b in uncurry add (3, 4) # => 7