Slice
Slice: Slice, empty, size, first, last, contains, indexOf, operator[], operator[-], data, iterator, print, enumerate, map, filter, chain, find, sum, all, any, none
Functions: operator==
struct Slice<Element>
A non-owning reference to a contiguous array of elements.
Slice
Slice()Initializes a Slice referring to an empty array.
implicit Slice(List<Element>& list)Initializes a Slice referring to the elements of the given List.
Slice(Element* data, int size)Initializes a Slice referring to an array of the given size located at the given memory address.
empty
bool empty()Returns true if the array has no elements.
size
int size()Returns the number of elements in the array.
first
Element& first()Returns the first element in the array.
last
Element& last()Returns the last element in the array.
contains
bool contains(Element& value)Returns true if the array contains an element equal to the given value.
indexOf
int? indexOf(Element& value)Returns the index of the first element equal to the given value, or null if it's not found.
operator[]
Element& operator[](int index)Returns a reference to 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; out-of-bounds access aborts in debug and release-safe builds.
data
Element[*] data()Returns a pointer to the first element.
iterator
ArrayIterator<Element> iterator()Returns an iterator over the elements.
void print(OutputStream& stream)Writes the elements to the given stream.
enumerate
EnumeratedIterator<Element> enumerate()Returns an iterator over the elements with their indices.
map
MappedIterator<Output, Element, ArrayIterator<Element>, Pred> map<Output, Pred: Output(Element&)>(Pred transform)Lazily transforms the elements. Collect the results with toList().
MappedIterator<Output, Element, ArrayIterator<Element>, Pred> map<Output, T: Copyable, Pred: Output(T)>(Pred transform)Lazily transforms the elements. Collect the results with toList().
filter
FilterIterator<Element, ArrayIterator<Element>, Pred> filter<Pred: bool(Element&)>(Pred include)Lazily keeps the elements satisfying the predicate. Collect the results with toList().
FilterIterator<Element, ArrayIterator<Element>, Pred> filter<T: Copyable, Pred: bool(T)>(Pred 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().
find
Element&? find<Pred: bool(Element&)>(Pred predicate)Returns the first element satisfying the predicate, or null.
Element&? find<T: Copyable, Pred: bool(T)>(Pred predicate)Returns the first element satisfying the predicate, or null.
sum
Element sum()Returns the sum of the elements, or zero if there are none.
all
bool all<Pred: bool(Element&)>(Pred predicate)Returns true if all elements satisfy the predicate.
bool all<T: Copyable, Pred: bool(T)>(Pred predicate)Returns true if all elements satisfy the predicate.
any
bool any<Pred: bool(Element&)>(Pred predicate)Returns true if any element satisfies the predicate.
bool any<T: Copyable, Pred: bool(T)>(Pred predicate)Returns true if any element satisfies the predicate.
none
bool none<Pred: bool(Element&)>(Pred predicate)Returns true if no element satisfies the predicate.
bool none<T: Copyable, Pred: bool(T)>(Pred predicate)Returns true if no element satisfies the predicate.
operator==
bool operator==<T>(T[] a, T[] b)Returns true if both arrays have equal elements.