Array
Array: size, print, data, toSlice, first, last, contains, indexOf, iterator, enumerate, find, map, filter, chain, sum, all, any, none, dot, lengthSquared, length, normalized
Functions: cross
struct Array<T, int N>
A fixed-size array holding N elements of type
T.
Unlike List, the size is part of the type, so arrays of
different sizes are different types. Array literals convert to arrays
when the size matches. The compiler lowers this fieldless declaration to
the native fixed-array representation, so Array<T, N>
and T[N] denote the same type.
size
int size()Returns the number of elements.
void print(OutputStream& stream)Writes the elements to the given stream.
data
T[*] data()Returns a pointer to the first element.
toSlice
implicit T[] toSlice()Converts to a Slice over the elements.
first
T& first()Returns the first element.
last
T& last()Returns the last element.
contains
bool contains(T& value)Returns true if the array contains an element equal to the given value.
indexOf
int? indexOf(T& value)Returns the index of the first element equal to the given value, or null if it's not found.
iterator
ArrayIterator<T> iterator()Returns an iterator over the elements.
enumerate
EnumeratedIterator<T> enumerate()Returns an iterator over the elements with their indices.
find
T&? find<Pred: bool(T&)>(Pred predicate)Returns the first element satisfying the predicate, or null.
T&? find<U: Copyable, Pred: bool(U)>(Pred predicate)Returns the first element satisfying the predicate, or null.
map
MappedIterator<Output, T, ArrayIterator<T>, Pred> map<Output, Pred: Output(T&)>(Pred transform)Lazily transforms the elements. Collect the results with toList().
MappedIterator<Output, T, ArrayIterator<T>, Pred> map<Output, U: Copyable, Pred: Output(U)>(Pred transform)Lazily transforms the elements. Collect the results with toList().
filter
FilterIterator<T, ArrayIterator<T>, Pred> filter<Pred: bool(T&)>(Pred include)Lazily keeps the elements satisfying the predicate. Collect the results with toList().
FilterIterator<T, ArrayIterator<T>, Pred> filter<U: Copyable, Pred: bool(U)>(Pred include)Lazily keeps the elements satisfying the predicate. Collect the results with toList().
chain
ChainIterator<T, ArrayIterator<T>, Other> chain<Other>(Other other)Lazily appends another iterator's elements. Collect the results with toList().
sum
T sum()Returns the sum of the elements, or zero if there are none.
all
bool all<Pred: bool(T&)>(Pred predicate)Returns true if all elements satisfy the predicate.
bool all<U: Copyable, Pred: bool(U)>(Pred predicate)Returns true if all elements satisfy the predicate.
any
bool any<Pred: bool(T&)>(Pred predicate)Returns true if any element satisfies the predicate.
bool any<U: Copyable, Pred: bool(U)>(Pred predicate)Returns true if any element satisfies the predicate.
none
bool none<Pred: bool(T&)>(Pred predicate)Returns true if no element satisfies the predicate.
bool none<U: Copyable, Pred: bool(U)>(Pred predicate)Returns true if no element satisfies the predicate.
dot
T dot(T[N] other)Returns the dot product of this array and other.
lengthSquared
T lengthSquared()Returns the squared Euclidean length of this array.
length
T length()Returns the Euclidean length of this array in the element type.
normalized
T[N] normalized()Returns this array scaled to unit length. Only meaningful for floating-point elements.
cross
T[3] cross<T>(T[3] a, T[3] b)Returns the cross product of two 3-element arrays.