Collection built-ins
These functions build and take apart [T] sequences.
list
list(first: T, rest: T...) -> [T]
Builds a sequence from one or more values of the same type.
| Argument | Type | Requirement | Description |
|---|---|---|---|
first | T | Required, positional | First element. Its type becomes the element type. |
rest | T... | Zero or more positional | Further elements, all of the same type as the first. |
Returns [T]. The values, in order.
let widths = list(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 [] works for any element type. |
Returns [T]. A new sequence starting with value.
let values = cons(10., cons(20., []));
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).