OxL Reference

data List

Dynamic array (§3.3). [a, b] literals have this type.

Example:

oxl✓ checked in CI
fn main() io {
  var xs = [3, 1, 2]
  xs.push(0)
  xs.sort()
  print("{xs} first={xs[0]} len={xs.len()}")
}
Output
[0, 1, 2, 3] first=0 len=4
@builtin("List") pub(api) data List<T>

Complexity. indexing and `push` O(1) (amortized), `insert`/`remove` O(n), `contains` O(n), `sort` O(n log n).

Thread safety. not shared between tasks; send a copy (or a `frozen` list) to another task.

Since. 1.0.0-beta

Methods

new() -> Self
Empty list.
len() -> usize
Number of elements.
isEmpty() -> bool
Whether the list has no elements.
push(x: T)
Appends an element.
pop() -> T?
Removes and returns the last element.
get(i: usize) -> T?
Element at i or none.
insert(i: usize, x: T)
Inserts x before the element at index i; later elements move one place up.
remove(i: usize) -> T
Removes and returns the element at index i; later elements move one place down.
clear()
Removes all elements.
contains(x: T) -> bool
Whether some element equals x.
reverse()
Reverses the order of the elements in place.
sort()
Stable sort by the natural order (Ord).
clone() -> List<T>
A copy of the list (elements are cloned too).
first() -> T?
The first element, or none for an empty list.
last() -> T?
The last element or none.
map(f: fn(T) -> U F) -> List<U> F
A new list with f applied to every element.
filter(p: fn(T) -> bool F) -> List<T> F
A new list with the elements for which p is true.
fold(start: A, f: fn(A, T) -> A F) -> A F
Folds the list from the left
any(p: fn(T) -> bool F) -> bool F
True when p holds for at least one element.
all(p: fn(T) -> bool F) -> bool F
True when p holds for every element.
count(p: fn(T) -> bool F) -> usize F
The number of elements for which p is true.
enumerate() -> List<(usize, T)>
Pairs every element with its index.
forEach(f: fn(T) F)
Calls f for every element.
iter() -> iter<T>
Lazy iterator over a snapshot of the list (D-2001)
intoIter() -> iter<T>
Lazy iterator that takes the list over (no copy).
sum() -> i64
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> i64
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> i64?
The smallest element, or none for an empty list.
max() -> i64?
The largest element, or none for an empty list.
sum() -> i32
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> i32
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> i32?
The smallest element, or none for an empty list.
max() -> i32?
The largest element, or none for an empty list.
sum() -> i16
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> i16
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> i16?
The smallest element, or none for an empty list.
max() -> i16?
The largest element, or none for an empty list.
sum() -> i8
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> i8
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> i8?
The smallest element, or none for an empty list.
max() -> i8?
The largest element, or none for an empty list.
sum() -> isize
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> isize
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> isize?
The smallest element, or none for an empty list.
max() -> isize?
The largest element, or none for an empty list.
sum() -> i128
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> i128
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> i128?
The smallest element, or none for an empty list.
max() -> i128?
The largest element, or none for an empty list.
sum() -> u64
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> u64
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> u64?
The smallest element, or none for an empty list.
max() -> u64?
The largest element, or none for an empty list.
sum() -> u32
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> u32
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> u32?
The smallest element, or none for an empty list.
max() -> u32?
The largest element, or none for an empty list.
sum() -> u16
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> u16
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> u16?
The smallest element, or none for an empty list.
max() -> u16?
The largest element, or none for an empty list.
sum() -> u8
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> u8
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> u8?
The smallest element, or none for an empty list.
max() -> u8?
The largest element, or none for an empty list.
sum() -> usize
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> usize
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> usize?
The smallest element, or none for an empty list.
max() -> usize?
The largest element, or none for an empty list.
sum() -> u128
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> u128
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> u128?
The smallest element, or none for an empty list.
max() -> u128?
The largest element, or none for an empty list.
sum() -> f64
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> f64
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> f64?
The smallest element, or none for an empty list.
max() -> f64?
The largest element, or none for an empty list.
sum() -> f32
The sum of the elements (0 for an empty list); panics on overflow like +.
product() -> f32
The product of the elements (1 for an empty list); panics on overflow like *.
min() -> f32?
The smallest element, or none for an empty list.
max() -> f32?
The largest element, or none for an empty list.
join(sep: str) -> str
Concatenation of the elements separated by sep.
sortBy(key: fn(T) -> K)
Stable sort by the natural order of key(x).

Defined in: std/core/types.oxl:25

See also