Skip to content

List

1 min read

Import: import system.collections;

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

insert

Inserts value at index, shifting later elements right. index == length appends. Returns false and leaves the list unchanged when index is outside 0 through length.

public fun insert(index: int, value: T): bool where T: unmanaged

remove_at

Removes the element at index, shifting later elements left. Returns true on success, or false if index is out of range (the list is left unchanged in that case).

public fun remove_at(index: int): bool

remove

Removes the first occurrence of value (by equality). Returns true when something was removed.

public fun remove(borrow value: T): bool

iterator

Enumerator for for (let x in list). Returns a fresh cursor over the current elements.

public fun iterator(): ListIterator<T>

as_span

A view of the current elements, writable in place. The span holds the backing array it was taken from: after the list grows (or shrinks and regrows) it keeps showing that old array, so take a fresh span after structural changes.

public fun as_span(): Span<T>

as_read_only_span

A read-only view of the current elements, with the same staleness rule as as_span.

public fun as_read_only_span(): ReadOnlySpan<T>

sort_by

Sorts the list in place with the supplied comparator.

public fun sort_by(borrow cmp: fun(T, T): int): void

sort

Sorts the list in place into ascending order using each element's compare method. Only attached when T : Comparable<T> (via where).

public fun sort(): void where T: Comparable<T>

Binary search over a list that is already sorted ascending (by compare). Returns the index of a matching element as Some(index), or None if value is not present. O(log n). Only attached when T : Comparable<T> (via where).

public fun binary_search(borrow value: T): Option<int> where T: Comparable<T>

to_string

Returns a text representation of this value.

public override fun to_string(): string