A grid with a hard border around the edges. you cant read or write from squares outside the border. Here is an example where such a grid is used: Space Invaders.
Trys modifying a grid and if its fails it returns the original grid.
Please be aware, that by using this function you might introduce errors.
A grid of values.
It has a fixed amount of columns and rows.
If case of a invalid position, it returns an error.
grid |> Grid.insert ( -1, 0 ) virus == Err OutOfBoundsInsert a value at a position in a grid. Returns a NotSuccessful error if
the position is occupied.
Update the value of a grid for a specific position with a given function.
Remove a vlaue from a grid. If the position is empty, it returs a
NotSuccessful error.
Get the value associated with a position. If the position is empty, return Nothing.
checks if a position is valid.
grid : Grid a
grid =
empty
{ columns=42
, rows=3
}
grid |> isValid (-1,0) --> False
grid |> isValid (41,0) --> True
grid |> isValid (42,0) --> Falsereturn the dimensions of the grid
Get all non empty positions in a grid, sorted from lowest to highest.
Get all empty positions in a grid, sorted from lowest to highest.
Convert a grid into an association list of position-value pairs, sorted by the position.
Convert an association list into a grid.
Convert an dictionary to a grid
Apply a function to all positions in a grid.
Fold over all positions in a grid, row by row, from top down.
Fold over all positions in a grid, row by row, from bottum up.
Partition a grid according to some test.
The first grid contains all values which passed the test, and the second contains the values that did not.
Find the first value that passes a given test.
Combine two grids. If there is a collision, preference is given to the first grid.
Keep a value when its position appears in the second grid. Preference is given to values in the first grid.
Possible Errors.
OutOfBounds- the position is not validNotSucessful- the function as a problem fullfilling the task. (Maybe the position is occupied?)