March Docs

Tuple

Tuple module: utilities for 2-tuples (pairs).

All functions operate on (a, b) pairs. Use let-destructuring to access components.

Functions

fnfirstfirst(t : (a, b)) : a#

Returns the first element of a pair.

fnsecondsecond(t : (a, b)) : b#

Returns the second element of a pair.

fnswapswap(t : (a, b)) : (b, a)#

Swaps the two elements of a pair.

fnmap_firstmap_first(t : (a, b), f : a -> c) : (c, b)#

Applies f to the first element, returning a new pair.

fnmap_secondmap_second(t : (a, b), f : b -> c) : (a, c)#

Applies f to the second element, returning a new pair.

fnmap_bothmap_both(t : (a, b), f : a -> c, g : b -> d) : (c, d)#

Applies f to the first element and g to the second element.

fnto_listto_list(t : (a, a)) : List(a)#

Converts a pair to a 2-element list. Both elements must be the same type.

fnmakemake(a : a, b : b) : (a, b)#

Creates a pair from two values.

fnapplyapply(t : (a, b), f : (a, b) -> c) : c#

Applies a function that takes two separate args to a pair.

fnbothboth(t : (a, b), p : a -> Bool, q : b -> Bool) : Bool#

Returns true if both elements satisfy their respective predicates.

fnzipzip(xs : List(a), ys : List(b)) : List((a, b))#

Zips two lists into a list of pairs. Stops at the shorter list.

fnunzipunzip(pairs : List((a, b))) : (List(a), List(b))#

Unzips a list of pairs into a pair of lists.