March Docs

Tuple

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

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

Functions

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

Applies f to the pair t as a single tuple argument: f(t).

(a, b) -> c is a function of ONE argument that is a pair — not a two-argument function, which March spells curried, a -> b -> c. To apply a two-argument function to a pair, destructure it: let (x, y) = t.

Examples

march> Tuple.apply((3, 4), fn p -> Tuple.first(p) * Tuple.second(p))
12
fnbothboth(t : (a, b), p : a -> Bool, q : b -> Bool) : Bool#

Returns true if p holds for the first element and q for the second. q is not called when p is false.

Examples

march> Tuple.both((1, "a"), fn x -> x > 0, fn s -> s == "a")
true
march> Tuple.both((1, "a"), fn x -> x > 0, String.is_empty)
false
fnfirstfirst(t : (a, b)) : a#

Returns the first element of a pair.

Examples

march> Tuple.first((1, "a"))
1
fnmakemake(a : a, b : b) : (a, b)#

Creates a pair from two values.

Examples

march> Tuple.make(1, "a")
(1, "a")
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, returning the new pair.

Examples

march> Tuple.map_both((1, "a"), fn x -> x * 10, String.to_uppercase)
(10, "A")
fnmap_firstmap_first(t : (a, b), f : a -> c) : (c, b)#

Applies f to the first element, returning a new pair; the second element is unchanged.

Examples

march> Tuple.map_first((1, "a"), fn x -> x + 1)
(2, "a")
fnmap_secondmap_second(t : (a, b), f : b -> c) : (a, c)#

Applies f to the second element, returning a new pair; the first element is unchanged.

Examples

march> Tuple.map_second((1, "a"), fn s -> s ++ "!")
(1, "a!")
fnsecondsecond(t : (a, b)) : b#

Returns the second element of a pair.

Examples

march> Tuple.second((1, "a"))
"a"
fnswapswap(t : (a, b)) : (b, a)#

Swaps the two elements of a pair.

Examples

march> Tuple.swap((1, "a"))
("a", 1)
fnto_listto_list(t : (a, a)) : List(a)#

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

Examples

march> Tuple.to_list((1, 2))
[1, 2]
fnunzipunzip(pairs : List((a, b))) : (List(a), List(b))#

Unzips a list of pairs into a pair of lists (first components, second components). Same result as List.unzip.

Examples

march> Tuple.unzip([(1, "a"), (2, "b")])
([1, 2], ["a", "b"])
march> Tuple.unzip([])
([], [])
fnzipzip(xs : List(a), ys : List(b)) : List((a, b))#

Zips two lists into a list of pairs. Stops at the shorter list. Same result as List.zip.

Examples

march> Tuple.zip([1, 2, 3], ["a", "b"])
[(1, "a"), (2, "b")]