Provides an ergonomic and fast way to use 2 dimensional arrays in Elm.
Type representing a 2 dimensional array.
fromRows : Array (Array a) -> Maybe (Array2D a)
Attempts to create a Array2D
from an Array
of Array
s representing rows.
Returns Nothing
when the rows' lengths don't match.
fromColumns : Array (Array a) -> Maybe (Array2D a)
Attempts to create a Array2D
from an Array
of Array
s representing columns.
Returns Nothing
when the columns' lengths don't match.
fromRowMajor : Basics.Int -> Basics.Int -> Array a -> Maybe (Array2D a)
Attempts to create a Array2D
from an Array
of elements and the rows and columns amounts.
Orders the elements in row major order.
The array has to be the same length as the product of the provided rows and columns.
initialize : Basics.Int -> Basics.Int -> (Basics.Int -> Basics.Int -> a) -> Array2D a
Creates an Array2D
with the provided rows and columns.
Each element is created using the provided function which gives the index (row and column).
repeat : Basics.Int -> Basics.Int -> a -> Array2D a
Creates a Array2D
with the provided rows and columns and fills it with the provided element.
rows : Array2D a -> Basics.Int
Gets the number of rows the Array2D
holds.
columns : Array2D a -> Basics.Int
Gets the number of columns the Array2D
holds.
length : Array2D a -> Basics.Int
Gets the total number of elements the Array2D
holds.
get : Basics.Int -> Basics.Int -> Array2D a -> Maybe a
Gets an element from the Array2D
at the provided row and column.
Returns Nothing
when the index is out of bounds.
set : Basics.Int -> Basics.Int -> a -> Array2D a -> Array2D a
Sets an element in the Array2D
at the provided row and column.
Returns the Array2D
unchanged if the index is out of bounds.
update : Basics.Int -> Basics.Int -> (a -> a) -> Array2D a -> Array2D a
Updates an element in the Array2D
with a function at the provided row and column.
Returns the Array2D
unchanged if the index is out of bounds.
map : (a -> b) -> Array2D a -> Array2D b
Applies a function to every element in the Array2D
.
indexedMap : (Basics.Int -> Basics.Int -> a -> b) -> Array2D a -> Array2D b
Applies a function to every element in the Array2D
.
The index (row and column) are provided to the mapping function.
toFlatArrayRowMajor : Array2D a -> Array a
Flattens the Array2D
in row major order.
generator : Random.Generator a -> Basics.Int -> Basics.Int -> Random.Generator (Array2D a)
Generates a Array2D
where each value is randomly generated.