Std.Pair
View source →Two-tuple helpers.
These operate on Cure tuples of the shape %[a, b], indexed via
:erlang.element/2. Most helpers round-trip cleanly with
Std.Vector, which stores its length/elements in a three-element
tuple.
Examples
use Std.Pair
let p = %[1, "one"]
first(p) # => 1
swap(p) # => %["one", 1]
map_first(p, fn(x) -> x * 10) # => %[10, "one"]
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn element(index: Int, tuple: Tuple) -> T extern
1-based BEAM tuple element accessor; delegates to
:erlang.element/2.indexis 1-indexed, matching Erlang. -
# fn first(pair: Tuple) -> T
First element of a pair.
-
# fn from_list(list: List(T)) -> Tuple
Turn a list into a pair. Exactly two elements map to
%[a, b]; single-element lists are duplicated; empty or longer lists fall back to%[0, 0]. Intended as a quick parser for simple inputs. -
# fn map_both(pair: Tuple, f: (A) -> C, g: (B) -> D) -> Tuple
Apply
fto the first element andgto the second. -
# fn map_first(pair: Tuple, f: (A) -> C) -> Tuple
Apply
fto the first element, leave the second alone. -
# fn map_second(pair: Tuple, f: (B) -> C) -> Tuple
Apply
fto the second element, leave the first alone. -
# fn second(pair: Tuple) -> T
Second element of a pair.
-
# fn swap(pair: Tuple) -> Tuple
Swap the elements of a pair:
%[a, b] -> %[b, a]. -
# fn to_list(pair: Tuple) -> List(T)
Turn a pair into a 2-element list.