List

List: List, ~List, size, empty, capacity, operator[], operator[-], operator[]=, operator[-]=, first, last, data, push, append, reserve, removeFirst, removeLast, pop, removeAt, iterator, enumerate, find, map, filter, chain, all, any, none

Functions: operator==

struct List<Element>

A resizable array.

List

List()

Initializes an empty list.

List(public int capacity)

Initializes an empty list with pre-allocated capacity.

List(int size, Element value)

Initializes a list containing size copies of the given value.

List(Element[] elements)

Initializes an list containing the elements of the given array.

List(public int uninitializedSize)

Initializes the list to contain the given number of uninitialized elements.

~List

~List()

Frees the elements and backing storage.

size

int size()

Returns the number of elements in the list.

empty

bool empty()

Returns true if the list has no elements, otherwise false

capacity

int capacity()

Returns the number of elements the list can store without allocating more memory.

operator[]

Element& operator[](int index)

Returns the element at the given index. Returns the element at the given index.

operator[-]

Element& operator[-](int index)

Returns a reference to the element at the given offset from the end. Offset 1 is the last element; offsets outside 1..size() abort.

operator[]=

void operator[]=(int index, Element element)

Sets the element at the given index.

operator[-]=

void operator[-]=(int index, Element element)

Sets the element at the given offset from the end. Offset 1 is the last element; offsets outside 1..size() abort.

first

Element& first()

Returns the first element.

last

Element& last()

Returns the last element.

data

Element[*] data()

Returns a pointer to the first element.

push

Element& push(Element element)

Adds the given element to the end of the list, returning a reference to it.

append

void append(Element[] elements)

Adds all elements from the given array to the end of the list.

reserve

void reserve(int minimumCapacity)

Ensures that the capacity is large enough to store the given number of elements.

removeFirst

Element removeFirst()

Removes the first element from the list and returns it. Other elements are moved towards the beginning of the list by one index.

Element? removeFirst(bool(Element&) shouldRemove)

Removes the first element satisfying the given condition and returns it, or null if none matches.

Element? removeFirst<T: Copyable>(bool(T) shouldRemove)

Removes the first element satisfying the given condition and returns it, or null if none matches.

removeLast

void removeLast()

Removes the last element from the list.

pop

Element pop()

Removes and returns the last element.

removeAt

Element removeAt(int index)

Removes the element at the given index from the list and returns it. Elements following the removed element are moved towards the beginning of the list by one index.

iterator

ArrayIterator<Element> iterator()

Returns an iterator over the elements.

enumerate

EnumeratedIterator<Element> enumerate()

Returns an iterator over the elements with their indices.

find

Element&? find(bool(Element&) predicate)

Returns the first element satisfying the predicate, or null.

Element&? find<T: Copyable>(bool(T) predicate)

Returns the first element satisfying the predicate, or null.

map

MappedIterator<Output, Element, ArrayIterator<Element>, Output(Element&)> map<Output>(Output(Element&) transform)

Lazily transforms the elements. Collect the results with toList().

MappedIterator<Output, Element, ArrayIterator<Element>, Output(T)> map<Output, T: Copyable>(Output(T) transform)

Lazily transforms the elements. Collect the results with toList().

filter

FilterIterator<Element, ArrayIterator<Element>, bool(Element&)> filter(bool(Element&) include)

Lazily keeps the elements satisfying the predicate. Collect the results with toList().

FilterIterator<Element, ArrayIterator<Element>, bool(T)> filter<T: Copyable>(bool(T) include)

Lazily keeps the elements satisfying the predicate. Collect the results with toList().

chain

ChainIterator<Element, ArrayIterator<Element>, Other> chain<Other>(Other other)

Lazily appends another iterator's elements. Collect the results with toList().

all

bool all(bool(Element&) predicate)

Returns true if all elements satisfy the predicate.

bool all<T: Copyable>(bool(T) predicate)

Returns true if all elements satisfy the predicate.

any

bool any(bool(Element&) predicate)

Returns true if any element satisfies the predicate.

bool any<T: Copyable>(bool(T) predicate)

Returns true if any element satisfies the predicate.

none

bool none(bool(Element&) predicate)

Returns true if no element satisfies the predicate.

bool none<T: Copyable>(bool(T) predicate)

Returns true if no element satisfies the predicate.

operator==

bool operator==<T>(List<T>& a, List<T>& b)

Returns true if both lists have equal elements.