Skip to main content

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.

ArgumentTypeRequirementDescription
valueTRequired, positionalNew first element.
tail[T]Required, positionalThe 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(sequence: [T]) -> T

Returns the first element of a sequence.

ArgumentTypeRequirementDescription
sequence[T]Required, positionalA 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.

ArgumentTypeRequirementDescription
sequence[T]Required, positionalA 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.

ArgumentTypeRequirementDescription
startIntRequired, positionalFirst value.
stopIntRequired, positionalExclusive upper bound.
stepIntRequired, positionalStep 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.