Grids are 2-dimensional arrays. The elements in a grid must have the same type.
Initializes a Grid. initialize w h f creates a grid of width w,
height 'h', with the elements at (i j) initialized to the result
of (f i j).
Creates an grid with a given width and height, filled with a default element.
Just (repeat 2 2 'a') == fromList[['a', 'a'], ['a', 'a']]Creates a grid from a List of List. If the input list is not well formed, this function will returns Nothing. fromList [['e','l','m'], ['e','l','m'], ['e','l','m']] -- A 3x3 (Maybe grid)
fromList [['e','l','m'],
['e','l','m'],
['e','l']] == NothingReturns Just the element at the index or Nothing if the index is out of range.
let grid = fromList [['a','b','c'],
['d','e','f'],
['g','h','i']]
in
Maybe.andThen (get 1 2) grid == Just 'h'
Maybe.andThen (get -1 2) grid == NothingSet the element at a particular index. Returns an updated grid. If the index is out of range, the grid is unaltered.
let grid = fromList [['a','b','c'],
['d','e','f'],
['g','h','i']]
grid2 = fromList [['a','b','c'],
['d','e','f'],
['g','a','i']]
in
Maybe.andThen (set 1 2 'a') grid == grid2Applies a function on every element in an array.
Maybe.map (map sqrt) (fromList [[1,4], [9,16]]) == fromList [[1,2], [3,4]]Applies a function on every element with its index as first and second arguments.
indexedMap (\x y e -> (x, y, e)) (repeat 2 2 1)
-- [[(0,0,1),(1,0,1)],
-- [(0,1,1),(1,1,1)]]
Grid represents immutable 2 dimensional arrays.