JoshuaHall/elm-2d-array/1.0.1

NOTE: the latest version is 1.0.3

SquareArray2D

Provides an ergonomic and fast way to use square 2 dimensional arrays in Elm.

Square 2D Arrays

Type representing a 2 dimensional square array.

Creation

fromRows : Array (Array a) -> Maybe (SquareArray2D a)

Attempts to create a SquareArray2D from an Array of Arrays 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 Arrays representing columns. Returns Nothing when the elements don't form a square.

fromRowMajor : 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 : Int -> (Int -> 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 : Int -> a -> SquareArray2D a

Creates a SquareArray2D with a provided side length and fills it with an element.

Query

Gets the side length of the SquareArray2D.

Gets the total number of elements the SquareArray2D holds.

get : Int -> 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.

Manipulation

set : Int -> 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 : Int -> 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.

Transform

map : (a -> b) -> SquareArray2D a -> SquareArray2D b

Applies a function to every element in the SquareArray2D.

indexedMap : (Int -> 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.

Arrays

Flattens the SquareArray2D in row major order.

Randomness

generator : Generator a -> Int -> Generator (SquareArray2D a)

Generates a SquareArray2D where each value is randomly generated.