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