Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

array

array

array -- one-dimensional immutable array

This is the result type of array(type, i32, i32 -> T) which creates an
initialized immutable array

Note: This uses dummy unit-type args to avoid
name clash with routine array(T,length,init).

Functions

create a list from this array

redefines:

create a list from this array starting at the given index
is this sequence known to be finite? For infinite sequences, features like
count diverge.

redefines:

is this Sequence known to be array backed? If so, this means that operations
like index[] are fast.
redefines Sequence.count for array,
reducing complexity from O(n) to O(1).

redefines:

collect the contents of this Sequence into an array

redefines:

apply f to all elements in this array

redefines:

reverse the order of the elements in this array

redefines:

create a list that consists of the elements of this Sequence except the first
n elements

For arrays, this has performance in O(1).

redefines:

§index [ ](i i32)
 => 
array.T
:
Any 
get the contents of this array at the given index
create a slice from this array's elements at index 'from' (included)
up to 'to' (excluded).

Complexity:
index access : O(1)
count : O(1)

redefines:

fold the elements of this array using the given monoid.

e.g., to sum the elements of an array of i32, use a.fold i32.sum

redefines:

§fold(i i32, s array.T, m Monoid array.T)
 => 
array.T
:
Any 
fold the elements of this array using the given monoid and initial value

Used to fold an array tail-recursively
a sequence of all valid indices to access this array. Useful e.g., for
`for`-loops:

for i in arr.indices do
§put(i i32, v array.T)
 => 
array array.T
:
Any 
create a new array with element i set to v. Grow the array in case i == length.

Complexity: O(array.this.length)
§put(i i32, v array.T, z array.T)
 => 
array array.T
:
Any 
create a new array with element i set to v. Grow the array in case i >= length.
New array elements at indices array.this.length..i-1 will be set to z.

Complexity: O(max(i, array.this.length))
map the array to a new array applying function f to all elements
variant of map which additionally passes the index to
the mapping function f
reverse the order of the elements in this array
get a list of tuples indices and elements in this array

Type Features

array -- create initialized one-dimensional immutable array