Array (elixir_array v2.1.0)
A wrapper module for Erlang's array.
Link to this section Summary
Functions
Gets the value used for uninitialized entries.
Check if two arrays are equal using ===.
Access behavior fetch/2 callback.
Fixes the size of the array. This prevents it from growing automatically upon insertion.
Folds the elements of the array using the given function and initial accumulator value. The elements are visited in order from the lowest index to the highest.
Folds the elements of the array right-to-left using the given function and initial accumulator value. The elements are visited in order from the highest index to the lowest.
Converts an Erlang's array to an array. All properties (size, elements, default value, fixedness) of the original array are preserved.
Equivalent to from_list(list, nil).
Converts a list to an extendible array.
default is used as the value for uninitialized entries of the array.
Equivalent to from_orddict(orddict, nil).
Converts an ordered list of pairs {index, value} to a corresponding extendible array.
default is used as the value for uninitialized entries of the array.
Gets the value of entry idx. If idx is not a nonnegative integer, or if the array has
fixed size and idx is larger than the maximum index, the call raises ArgumentError.
Access behavior get/3 callback
Access behavior get_and_update/3 callback
Returns true if arr appears to be an array, otherwise false.
Note that the check is only shallow; there is no guarantee that arr is a well-formed array
representation even if this function returns true.
Checks if the array has fixed size. Returns true if the array is fixed, otherwise false.
Maps the given function onto each element of the array. The elements are visited in order from the lowest index to the highest.
Creates a new, extendible array with initial size zero. The default value is the atom nil, not undefined.
Creates a new fixed array according to the given options. By default, the array is extendible and has initial size zero. The default value is the atom nil, if not specified.
Access behavior pop/2 callback
Makes the array resizable.
Resets entry idx to the default value for the array.
If the value of entry idx is the default value the array will be returned unchanged.
Reset will never change size of the array. Shrinking can be done explicitly by calling resize/2.
Changes the size of the array to that reported by sparse_size/1.
If the given array has fixed size, the resulting array will also have fixed size.
Changes the size of the array.
If size is not a nonnegative integer, the call raises ArgumentError.
If the given array has fixed size, the resulting array will also have fixed size.
Sets entry idx of the array to val.
If idx is not a nonnegative integer, or if the array has fixed size and idx is
larger than the maximum index, the call raises ArgumentError.
Gets the number of entries in the array.
Entries are numbered from 0 to size(array)-1; hence, this is also the index of
the first entry that is guaranteed to not have been previously set.
Folds the elements of the array using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.
Folds the elements of the array right-to-left using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the highest index to the lowest.
Maps the given function onto each element of the array, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.
Gets the number of entries in the array up until the last non-default valued entry.
In other words, returns idx+1 if idx is the last non-default valued entry in the array,
or zero if no such entry exists.
Converts the array to a list, skipping default-valued entries.
Converts the array to an ordered list of pairs {index, value}, skipping default-valued entries.
Converts the array to its underlying Erlang's array.
Converts the array to a list.
Converts the array to an ordered list of pairs {index, value}.
Link to this section Types
element()
Specs
element() :: any()
index()
Specs
index() :: non_neg_integer()
opt()
Specs
opt() ::
{:fixed, boolean()}
| :fixed
| {:default, any()}
| {:size, non_neg_integer()}
| non_neg_integer()
opts()
Specs
orddict()
Specs
Specs
t() :: %Array{content: :array.array()}
Link to this section Functions
default(array)
Specs
Gets the value used for uninitialized entries.
equal?(array1, array2)
Specs
Check if two arrays are equal using ===.
fetch(arr, idx)
Access behavior fetch/2 callback.
fix(arr)
Specs
Fixes the size of the array. This prevents it from growing automatically upon insertion.
foldl(array, acc, fun)
Specs
Folds the elements of the array using the given function and initial accumulator value. The elements are visited in order from the lowest index to the highest.
If fun is not a function, the call raises ArgumentError.
foldr(array, acc, fun)
Specs
Folds the elements of the array right-to-left using the given function and initial accumulator value. The elements are visited in order from the highest index to the lowest.
If fun is not a function, the call raises ArgumentError.
from_erlang_array(erl_arr)
Specs
from_erlang_array(:array.array()) :: t()
Converts an Erlang's array to an array. All properties (size, elements, default value, fixedness) of the original array are preserved.
If erl_arr is not an Erlang's array, the call raises ArgumentError.
from_list(list)
Specs
Equivalent to from_list(list, nil).
from_list(list, default)
Specs
Converts a list to an extendible array.
default is used as the value for uninitialized entries of the array.
If list is not a proper list, the call raises ArgumentError.
from_orddict(orddict)
Specs
Equivalent to from_orddict(orddict, nil).
from_orddict(orddict, default)
Specs
Converts an ordered list of pairs {index, value} to a corresponding extendible array.
default is used as the value for uninitialized entries of the array.
If orddict is not a proper, ordered list of pairs whose first elements are nonnegative integers,
the call raises ArgumentError.
get(array, idx)
Specs
Gets the value of entry idx. If idx is not a nonnegative integer, or if the array has
fixed size and idx is larger than the maximum index, the call raises ArgumentError.
get(arr, idx, value)
Access behavior get/3 callback
get_and_update(arr, idx, fun)
Access behavior get_and_update/3 callback
is_array(arr)
Specs
Returns true if arr appears to be an array, otherwise false.
Note that the check is only shallow; there is no guarantee that arr is a well-formed array
representation even if this function returns true.
is_fix(array)
Specs
Checks if the array has fixed size. Returns true if the array is fixed, otherwise false.
map(arr, fun)
Specs
Maps the given function onto each element of the array. The elements are visited in order from the lowest index to the highest.
If fun is not a function, the call raises ArgumentError.
new()
Specs
new() :: t()
Creates a new, extendible array with initial size zero. The default value is the atom nil, not undefined.
new(options)
Specs
Creates a new fixed array according to the given options. By default, the array is extendible and has initial size zero. The default value is the atom nil, if not specified.
options is a single term or a list of terms, selected from the following:
n : non_neg_integeror{:size, n : non_neg_integer}- Specifies the initial size of the array; this also implies
{:fixed, true}. Ifnis not a nonnegative integer, the call raisesArgumentError.
- Specifies the initial size of the array; this also implies
:fixedor{:fixed, true}- Creates a fixed-size array.
{:fixed, false}- Creates an extendible (non fixed-size) array.
{:default, value}- Sets the default value for the array to
value.
- Sets the default value for the array to
pop(arr, idx)
Access behavior pop/2 callback
relax(arr)
Specs
Makes the array resizable.
reset(arr, idx)
Specs
Resets entry idx to the default value for the array.
If the value of entry idx is the default value the array will be returned unchanged.
Reset will never change size of the array. Shrinking can be done explicitly by calling resize/2.
If idx is not a nonnegative integer, or if the array has fixed size and idx is
larger than the maximum index, the call raises ArgumentError.
resize(arr)
Specs
Changes the size of the array to that reported by sparse_size/1.
If the given array has fixed size, the resulting array will also have fixed size.
resize(arr, size)
Specs
resize(t(), non_neg_integer()) :: t()
Changes the size of the array.
If size is not a nonnegative integer, the call raises ArgumentError.
If the given array has fixed size, the resulting array will also have fixed size.
set(arr, idx, val)
Specs
Sets entry idx of the array to val.
If idx is not a nonnegative integer, or if the array has fixed size and idx is
larger than the maximum index, the call raises ArgumentError.
size(array)
Specs
size(t()) :: non_neg_integer()
Gets the number of entries in the array.
Entries are numbered from 0 to size(array)-1; hence, this is also the index of
the first entry that is guaranteed to not have been previously set.
sparse_foldl(array, acc, fun)
Specs
Folds the elements of the array using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.
If fun is not a function, the call raises ArgumentError.
sparse_foldr(array, acc, fun)
Specs
Folds the elements of the array right-to-left using the given function and initial accumulator value, skipping default-valued entries. The elements are visited in order from the highest index to the lowest.
If fun is not a function, the call raises ArgumentError.
sparse_map(arr, fun)
Specs
Maps the given function onto each element of the array, skipping default-valued entries. The elements are visited in order from the lowest index to the highest.
If fun is not a function, the call raises ArgumentError.
sparse_size(array)
Specs
sparse_size(t()) :: non_neg_integer()
Gets the number of entries in the array up until the last non-default valued entry.
In other words, returns idx+1 if idx is the last non-default valued entry in the array,
or zero if no such entry exists.
sparse_to_list(array)
Specs
Converts the array to a list, skipping default-valued entries.
sparse_to_orddict(array)
Specs
Converts the array to an ordered list of pairs {index, value}, skipping default-valued entries.
to_erlang_array(array)
Specs
to_erlang_array(t()) :: :array.array()
Converts the array to its underlying Erlang's array.
to_list(array)
Specs
Converts the array to a list.
to_orddict(array)
Specs
Converts the array to an ordered list of pairs {index, value}.