Array
Allows storing a collection of multiple elements under a single variable.
obj Array {
empty: bool
first: ref Element
last: ref Element
len: int
}
empty - Whether array has elements.
first - Reference to first element. If empty will throw an error.
last - Reference to last element. If empty will throw an error.
len - Number of elements.
Array.[]
Accesses element by index and returns its reference.
Array.[idx: int] ref Element
Array.clear()
Removes all elements and changes length to zero.
fn Array.clear () ref Self
Array.concat()
Concatenates two arrays into one and returns resulting array.
fn Array.concat (other: Self) Self
other - Another arrays you want to concatenate.
Array.contains()
Checks whether certain element exists.
fn Array.contains (search: Element) bool
search - Element to check if exists.
Array.filter()
Calls predicate
on every element and constructs array copy out of elements that passed the test.
fn Array.filter (predicate: (it: Element) -> bool) Self
predicate - Function to execute on each element of the array. Should return a truthy value to keep the element in the resulting array.
Array.forEach()
Calls iterator
on every element.
fn Array.forEach (iterator: (it: Element, idx: int) -> void) void
iterator - Function to execute on each element of the array.
Array.join()
Calls str
method on every element and joins result with separator.
fn Array.join (separator := ",") str
separator - Elements separator. The default is comma string.
Array.merge()
Merges other array’s elements into calling array.
fn Array.merge (other: Self) ref Self
other - Another array you want to merge.
Array.pop()
Removes last element and returns it.
fn Array.pop () Element
Array.push()
Adds new elements.
fn Array.push (elements: Element...) void
elements - New elements to add.
Array.remove()
Removes elements corresponding to specific indexes from array.
fn Array.remove (index: int) ref Self
index - Element index to remove.
Array.reverse()
Returns reversed array copy.
fn Array.reverse () Self
Array.slice()
Extracts array slice from start
to end
(end
not included).
fn Array.slice (start := 0, end := self.len) Self
start - Index at which to start extraction. The default is zero.
0
value is used.end - Index at which to end extraction. The default is array length.
0
value is used.start
then nothing is extracted.Array.sort()
Sorts the elements of the array in place.
fn Array.sort (comparator: (a: Element, b: Element) -> int) ref Self
comparator - Function that defines the sort order.
Array.str()
Returns a string representation.
fn Array.str () str