Implements 2D array using nested Arrays. Useful for implementing data grids, as it specifically provides row and column operations.
Cells are accessed by row, then column. Otherwise, it works very similarly to the Array class. The documentation examples usually omit converting Lists to Arrays for brevity.
Array2D's can be constructed from an Array or List of rows, where each row is an Array or List of cells. Behavior if the nested arrays happen to be jagged is currently undefined / handled poorly, so don't do this!
Array2D.fromList [["Row 1-Col 1", "Row 1-Col 2"], ["Row 2-Col 1", "Row 2-Col 2"]]Create an empty Array2D
Create an Array2D from an Array of Arrays.
let
row1 = Array.fromList [1, 2]
row2 = Array.fromList [2, 3]
in
fromArray (Array.fromList [row1, row2])Create an Array2D from a List of Lists.
fromList [[1, 2, 3], [4, 5, 6]]Create a 2D of a given size, filled with a default element. Similar to Array.repeat
repeat 2 3 0 == [[0, 0, 0], [0, 0, 0]]Get the number of rows in an Array2D
rows [[1, 2, 3], [4, 5, 6]] == 2Get the number of columns in an Array2D
columns [[1, 2, 3], [4, 5, 6]] == 3Check if an Array2D is empty.
isEmpty [] == TrueGet a cell.
get 1 1 [[1, 2], [3, 4]] == Just 4Update a cell, returning the changed Array2D.
set 0 0 -100 [[1, 2], [3, 4]] == [[-100, 2], [3, 4]]Get an individual row
getRow 1 [[1, 2], [3, 4]] == Just [3, 4]Append a row
appendRow [3, 4] [[1, 2]] == [[1, 2], [3, 4]]Delete a row
get column-th cell of each row as an Array
getColumn 1 [[1, 2], [3, 4]] == [Just 2, Just 4]Delete a column
2D version of Array.map.
map (\cell -> toString cell) [[1, 2], [3, 4]] == [["1", "2"], ["3", "4"]]2D version of Array.indexedMap. First two arguments of map function are the row and column.
indexedMap (\row column cell -> toString row) [[1, 2], [3, 4]] == [["0", "0"], ["1", "1"]]
Base Array2D type