Collection built-ins
These functions build and take apart [T] sequences. A sequence is written directly as a literal, so there is no constructor function:
let widths = [80., 120., 160.];
cons
cons(value: T, tail: [T]) -> [T]
Prepends one value to an existing sequence.
| Argument | Type | Requirement | Description |
|---|---|---|---|
value | T | Required, positional | New first element. |
tail | [T] | Required, positional | The rest of the sequence. The empty literal [] takes its element type from the head. |
Returns [T]. A new sequence starting with value.
let values = cons(10., [20., 30.]);
head
head(sequence: [T]) -> T
Returns the first element of a sequence.
| Argument | Type | Requirement | Description |
|---|---|---|---|
sequence | [T] | Required, positional | A non-empty sequence. |
Returns T. The first element.
Fails at run time if the sequence is empty.
tail
tail(sequence: [T]) -> [T]
Returns every element after the first.
| Argument | Type | Requirement | Description |
|---|---|---|---|
sequence | [T] | Required, positional | A non-empty sequence. |
Returns [T]. Everything after the first element.
Fails at run time if the sequence is empty.
range_full
range_full(start: Int, stop: Int, step: Int) -> [Int]
Builds an integer range from a start, stop, and step.
| Argument | Type | Requirement | Description |
|---|---|---|---|
start | Int | Required, positional | First value. |
stop | Int | Required, positional | Exclusive upper bound. |
step | Int | Required, positional | Step between values. |
Returns [Int]. The range as a sequence.
For the common case of counting from zero, use std::range(stop).
Sequence helpers
seq_len, seq_concat, seq_flatten, seq_sum, seq_any, and seq_all back std::len, std::concat, std::flatten, std::sum, std::any, and std::all, which take the same arguments. Each runs in one step, however long its input.