Std. Tuple
(Cure Standard Library v0.37.2)
View Source
Fixed-size heterogeneous tuples (%[a, b, ...]): the Tuple type and
positional accessors such as first, second, third and swap.
Tuple(T, U) is the arity-2 product — a flat BEAM {a, b} — and
Tuple(T1, …, Tn) (3 ≤ n ≤ 8) are the flat n-ary products. A tuple
literal is written %[a, b, …] and projected with .1, .2, … .
Arity-2 aliases the non-dependent dependent-pair, so the later
position may depend on the earlier one; the n-ary families are plain
flat products. This module is the honest replacement for the old
Std.Pair. The n-ary accessors (third, …) land alongside the
n-ary literal surface.
Examples
use Std.Tuple
first(%[1, 2]) # => 1
second(%[1, 2]) # => 2
swap(%[1, 2]) # => %[2, 1]
third(%[1, 2, 3]) # => 3
Summary
Functions
The first component of a pair.
The second component of a pair.
Swap the two components of a pair.
The third component of a 3-tuple.
Functions
fn first(t: Tuple(a, b)) -> a
The first component of a pair.
fn second(t: Tuple(a, b)) -> b
The second component of a pair.
fn swap(t: Tuple(a, b)) -> Tuple(b, a)
Swap the two components of a pair.
fn third(t: Tuple(a, b, c)) -> c
The third component of a 3-tuple.