Reference

List

Constructor

Input A list of elements separated by comma.
Output A list containing all the elements.

Signature

[Any, Any, Any, ...]: List

Example

[1, 2, 3] // returns [1, 2, 3]

Indexing

Input A list and a number representing the index.
Output The element at the specified index in the list.

Signature

List[Number]: Any

Example

[10, 20, 30][1] // returns 20

Filled

Input A number and any value.
Output A list filled with the specified value, repeated the specified number of times.

Signature

list_filled(a: Number, b: Any): List

Example

list_filled(3, 0) // returns [0, 0, 0]

At

Input A list and a number representing the index.
Output The element at the specified index in the list.

Signature

list_at(a: List, b: Number): Any

Example

list_at([10, 20, 30], 1) // returns 20

First

Input A list.
Output The first element of the list.

Signature

list_first(a: List): Any

Example

list_first([10, 20, 30]) // returns 10

Last

Input A list.
Output The last element of the list.

Signature

list_last(a: List): Any

Example

list_last([10, 20, 30]) // returns 30

Sublist

Input A list and two numbers representing the start and end indices.
Output A new list from the start index (inclusive) to the end index (exclusive).

Signature

list_sublist(a: List, b: Number, c: Number): List

Example

list_sublist([10, 20, 30, 40], 1, 3) // returns [20, 30]

Init

Input A list.
Output A new list containing all elements except the last one.

Signature

list_init(a: List): List

Example

list_init([1, 2, 3]) // returns [1, 2]

Rest

Input A list.
Output A new list containing all elements except the first one.

Signature

list_rest(a: List): List

Example

list_rest([1, 2, 3]) // returns [2, 3]

Take

Input A list and a number.
Output A new list containing the first n elements of the input list, where n is the specified number.

Signature

list_take(a: List, b: Number): List

Example

list_take([1, 2, 3, 4], 2) // returns [1, 2]

Drop

Input A list and a number.
Output A new list containing all elements except the first n elements, where n is the specified number.

Signature

list_drop(a: List, b: Number): List

Example

list_drop([1, 2, 3, 4], 2) // returns [3, 4]

Set

Input A list, a number, and any value.
Output A new list with the value set at the specified index.

Signature

list_set(a: List, b: Number, c: Any): List

Example

list_set([1, 2, 3], 1, 99) // returns [1, 99, 3]

Concatenation

Input Two lists.
Output A new list that is the result of concatenating the two lists.

Signature

list_concat(a: List, b: List): List

Example

list_concat([1, 2], [3, 4]) // returns [1, 2, 3, 4]

Insert start

Input A list and any value.
Output A new list with the value inserted at the start.

Signature

list_insertStart(a: List, b: Any): List

Example

list_insertStart([2, 3], 1) // returns [1, 2, 3]

Insert end

Input A list and any value.
Output A new list with the value inserted at the end.

Signature

list_insertEnd(a: List, b: Any): List

Example

list_insertEnd([1, 2], 3) // returns [1, 2, 3]

Remove

Input A list and an equatable value.
Output A new list with all the occurrences of the value removed.

Signature

list_remove(a: List, b: Equatable): List

Example

list_remove([1, 2, 3, 2], 2) // returns [1, 3]

Remove at

Input A list and a number.
Output A new list with the element at the specified index removed.

Signature

list_removeAt(a: List, b: Number): List

Example

list_removeAt([1, 2, 3], 1) // returns [1, 3]

Reverse

Input A list.
Output A new list with the elements in reverse order.

Signature

list_reverse(a: List): List

Example

list_reverse([1, 2, 3]) // returns [3, 2, 1]

Flatten

Input A list of lists.
Output A new list with nested lists flattened into a single list.

Signature

list_flatten(a: List): List

Example

list_flatten([[1, 2], [3, 4]]) // returns [1, 2, 3, 4]

Distinct

Input A list.
Output A new list with duplicate elements removed, preserving order.

Signature

list_distinct(a: List): List

Example

list_distinct([1, 2, 2, 3, 1]) // returns [1, 2, 3]

Chunk

Input A list and a number representing the chunk size.
Output A list of lists, each containing at most n elements.

Signature

list_chunk(a: List, b: Number): List

Example

list_chunk([1, 2, 3, 4, 5], 2) // returns [[1, 2], [3, 4], [5]]

Swap

Input A list and two numbers.
Output A new list with the elements at the specified indices swapped.

Signature

list_swap(a: List, b: Number, c: Number): List

Example

list_swap([1, 2, 3], 0, 2) // returns [3, 2, 1]

Join

Input A list and a string.
Output A string that is the result of concatenating the list elements, separated by the specified string.

Signature

list_join(a: List, b: String): String

Example

list_join(["a", "b", "c"], ", ") // returns "a, b, c"

Length

Input A list.
Output The number of elements in the list.

Signature

list_length(a: List): Number

Example

list_length([1, 2, 3]) // returns 3

Is empty

Input A list.
Output True if the list is empty. False otherwise.

Signature

list_isEmpty(a: List): Boolean

Example

list_isEmpty([]) // returns true

Is not empty

Input A list.
Output True if the list is not empty. False otherwise.

Signature

list_isNotEmpty(a: List): Boolean

Example

list_isNotEmpty([1, 2]) // returns true

Contains

Input A list and an equatable value.
Output True if the list contains the specified value. False otherwise.

Signature

list_contains(a: List, b: Equatable): Boolean

Example

list_contains([1, 2, 3], 2) // returns true

Index of

Input A list and an equatable value.
Output The index of the first occurrence of the value in the list, or -1 if the value is not found.

Signature

list_indexOf(a: List, b: Equatable): Number

Example

list_indexOf([10, 20, 30], 20) // returns 1

Map

Input A list and a function that takes an element of the list as input and returns a new value.
Output A new list with the function applied to each element of the input list.

Signature

list_map(a: List, b: Function): List

Example

list_map([1, 2, 3], double) // returns [2, 4, 6]

Filter

Input A list and a function that takes an element of the list as input and returns a boolean.
Output A new list containing only the elements of the input list for which the function returns true.

Signature

list_filter(a: List, b: Function): List

Example

list_filter([1, 2, 3, 4], isEven) // returns [2, 4]

Count

Input A list and a predicate function.
Output The number of elements matching the predicate.

Signature

list_count(a: List, b: Function): Number

Example

list_count([1, 2, 3, 4], num_isEven) // returns 2

Reduce

Input A list, an initial value, and a function that takes the current value and an element of the list as input and returns a new value.
Output The result of applying the function to each element of the list, starting with the initial value.

Signature

list_reduce(a: List, b: Any, c: Function): Any

Example

list_reduce([1, 2, 3], 0, num_add) // returns 6

All

Input A list and a function that takes an element of the list as input and returns a boolean.
Output True if the function returns true for all elements of the list. False otherwise.

Signature

list_all(a: List, b: Function): Boolean

Example

list_all([2, 4, 6], num_isEven) // returns true

None

Input A list and a function that takes an element of the list as input and returns a boolean.
Output True if the function returns false for all elements of the list. False otherwise.

Signature

list_none(a: List, b: Function): Boolean

Example

list_none([1, 3, 5], num_isEven) // returns true

Any

Input A list and a function that takes an element of the list as input and returns a boolean.
Output True if the function returns true for at least one element of the list. False otherwise.

Signature

list_any(a: List, b: Function): Boolean

Example

list_any([1, 2, 3], num_isEven) // returns true

Zip

Input Two lists and a function that takes an element from each list as input and returns a new value.
Output A new list with the function applied to each pair of elements from the input lists.

Signature

list_zip(a: List, b: List, c: Function): List

Example

list_zip([1, 2], [3, 4], num_add) // returns [4, 6]

Sort

Input A list and a function that takes two elements of the list as input and compares them.
Output A new list with the elements sorted according to the function.

Signature

list_sort(a: List, b: Function): List

Example

list_sort([3, 1, 2], num_compare) // returns [1, 2, 3]