Tuple
Tuple module: utilities for 2-tuples (pairs).
All functions operate on (a, b) pairs. Use let-destructuring to access components.
Functions
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))
12Returns 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)
falseReturns the first element of a pair.
Examples
march> Tuple.first((1, "a"))
1Creates a pair from two values.
Examples
march> Tuple.make(1, "a")
(1, "a")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")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")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!")Returns the second element of a pair.
Examples
march> Tuple.second((1, "a"))
"a"Swaps the two elements of a pair.
Examples
march> Tuple.swap((1, "a"))
("a", 1)Converts a pair to a 2-element list. Both elements must be the same type.
Examples
march> Tuple.to_list((1, 2))
[1, 2]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([])
([], [])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")]