List

Overview

The List object is the primary container for a dynamically-sized sequence of values. Lists are also implicitly iterable and can be used directly with for-in loop statements.

Fields

.size

fn -> Number

Gets the number of elements in a List value.

.empty

fn -> Boolean

Determines if a List has no elements.

.front

fn -> T

Gets the first element of a List value.

.back

fn -> T

Gets the last element of a List value.

.get

fn (index: Number) -> T

Gets an element from a List by index.

.set

fn (index: Number, value: T) -> T

Sets an element in a List by index.

.map

fn [V = Any](callback: fn (T?, Number?) -> V) -> List[V]

Mutates each element in a List with a given transformation callback.

.fold

fn [V = Any](initial: V, callback: fn (V, T) -> V) -> V

Reduces all elements in a List to an accumulated value.

.erase

fn (start?: Number, end?: Number) -> List[T]

Removes elements from a List indicated by a given range.

.slice

fn (start?: Number, end?: Number) -> List[T]

Creates a section of a List indicated by a given range.

.filter

fn (callback?: (T) -> Boolean) -> List[T]

Filters a List with a given predicate callback.

.reverse

fn -> List[T]

Reverses a List value.

.push_front

fn (...values: T) -> Number

Pushes values onto a List from the front.

.push_back

fn (...values: T) -> Number

Pushes values onto a List from the back.

.pop_front

fn -> T

Pops the first element from a List value.

.pop_back

fn -> T

Pops the last element from a List value.

.first_index_of

fn (needle: T) -> Number

Finds the index of the first element in a List that matches a given needle.

.last_index_of

fn (needle: T) -> Number

Finds the index of the last element in a List that matches a given needle.

Statics

.from

fn [T](...values: T) -> List[T]

Creates a List from a collection of values.

.empty

fn [T = Any] -> List[T]

Creates an empty List value.

.range

fn (start?: Number, end?: Number, step?: Number) -> List[Number]

Creates a ranged List value.

.filled

fn [V](size: Number, value: V) -> List[V]

Creates a List filled to a size with a given value.

On this page