List
sealed class List<T>import List from Wax;A growable, contiguous collection. Adding elements expands its capacity as needed.
Use WithCapacity when the expected size is known. size counts initialized
elements; capacity counts the available slots. Spans view the current backing
storage and do not follow a later reallocation.
import List from Wax;
api fn Main() : int32 {
var values = new List<int32>();
values.Add(3);
values.Add(1);
values.Sort();
return values[0];
}
Inherits from object. Follow these links for inherited members.
Members
constructorconstructor
public constructor ()Creates an empty collection. No elements are inserted.
WithCapacityconstructor
public constructor WithCapacity (int32 capacity)Creates an empty collection with reserved storage. Capacity reservation does not change the element count.
sizegetter
public get size() : int32The number of live elements; valid element indices are [0, size). Capacity is not part of
the readable range.
capacitygetter
public get capacity() : int32The number of elements the current backing storage can hold before growth.
EnsureCapacitymethod
public fn EnsureCapacity(int32 capacity) : voidEnsures room for at least capacity elements without changing size.
EnsureAdditionalCapacitymethod
public fn EnsureAdditionalCapacity(int32 additional) : voidReserves space for the current element count plus additional. Does not insert elements.
Addmethod
public fn Add(T item) : voidAppends one element, growing the backing storage when necessary.
thisindexer-getter
public get this(int32 index) : TReads or replaces a live element at a zero-based index. An index outside [0, size) panics.
Replacing an element does not change the collection size.
thisindexer-setter
public set this(int32 index, T value) : voidReads or replaces a live element at a zero-based index. An index outside [0, size) panics.
Replacing an element does not change the collection size.
ToSpanmethod
public fn ToSpan() : Span<T>Borrows a mutable view of the current live elements without copying. The view has a fixed length. Writes affect shared storage; it does not follow a later collection reallocation.
ToReadOnlySpanmethod
public fn ToReadOnlySpan() : ReadOnlySpan<T>Borrows the current live elements without copying or permitting writes through this view. Other aliases can still mutate the storage; the view does not follow a later reallocation.
AddRangemethod
public fn AddRange(scoped ReadOnlySpan<T> items) : voidAppends source elements in order, growing storage as needed. Source views over the old backing remain valid during growth. An empty source does nothing.
InsertAtmethod
public fn InsertAt(int32 index, T item) : voidInserts at an index between zero and size, shifting later elements right. Invalid indices
panic. Inserting at size appends.
RemoveAtmethod
public fn RemoveAt(int32 index) : voidRemoves an in-range element and shifts the surviving tail left. Invalid indices panic.
Clearmethod
public fn Clear() : voidRemoves all live elements while keeping the backing capacity.
RemoveAllmethod
public fn RemoveAll(fn<(T) : bool> predicate) : int32Removes items for which the predicate returns true, preserving survivor order, and returns the number removed. The predicate must not structurally modify this list.
ToArraymethod
public fn ToArray() : T[]Returns a separate array snapshot of the live elements. Reference elements still point to the same objects.
Slicemethod
public fn Slice(int32 start, int32 len) : Span<T>Borrows a mutable window [start, start + len). Negative arguments or a range outside the
live elements panic. An empty slice at size is valid.
Sortmethod
public fn Sort() : void where T is ComparableSorts in place using the element comparison. The ordering is deterministic but not stable.
SortBymethod
public fn SortBy(fn<(T,T) : int32> compare) : voidSorts in place using a comparator returning a negative value, zero, or a positive value for less, equal, or greater. The comparator must provide a consistent ordering. Equal elements may be reordered.
SortStablemethod
public fn SortStable() : void where T is ComparableSorts in place while preserving the order of equal elements.
SortStableBymethod
public fn SortStableBy(fn<(T,T) : int32> compare) : voidSorts in place with a consistent negative/zero/positive comparator, preserving the original order of equal elements. Larger inputs allocate a scratch array.
Containsmethod
public fn Contains(T item) : bool where T is EquatableReturns whether the collection contains an equal element.
IndexOfmethod
public fn IndexOf(T item) : int32 where T is EquatableReturns the first matching index, or -1 when the element is absent.
LastIndexOfmethod
public fn LastIndexOf(T item) : int32 where T is EquatableReturns the last matching element index using Equals, or -1 when absent, including an
empty view.
Fillmethod
public fn Fill(T value) : voidAssigns value to every element of the backing window. An empty view does nothing.
Reference elements all receive the same reference.
FillRangemethod
public fn FillRange(T value, int32 start, int32 count) : voidFills [start, start + count) with value. Both endpoints must lie in [0, size]; invalid
endpoints panic before any write. An empty or reversed range whose endpoints are valid
performs no writes.
CopyTomethod
public fn CopyTo(Span<T> dest) : voidCopies the first min(size, dest.length) elements into dest, safely handling overlapping
views. A shorter destination truncates the copy without a panic; any remaining destination
elements are unchanged. An empty source or destination does nothing. Reference elements copy
their references, not the referenced objects.
Reversemethod
public fn Reverse() : voidReverses the element order in place.
BinarySearchmethod
public fn BinarySearch(T item) : int32 where T is ComparableSearches a view already sorted ascending under CompareTo. Returns a matching element
index; when duplicates exist, the chosen match is unspecified. If absent, returns
~insertionIndex; apply ~ again to recover the insertion position. An empty view returns
-1 (~0).
Removemethod
public fn Remove(T item) : bool where T is EquatableRemoves the first element equal to the item and returns true, or returns false if no match exists.