Islands.Grid (Islands Grid v0.1.20) View Source
A grid (map of maps) and functions for the Game of Islands.
Inspired by the book Functional Web Development by Lance Halvorsen.
Link to this section Summary
Functions
Creates an "empty" grid.
Converts a board or guesses struct into a grid.
Converts a board or guesses struct into a list of maps.
Link to this section Types
Specs
t() :: %{ required(Islands.Coord.row()) => %{required(Islands.Coord.col()) => atom()} }
A grid (map of maps) allowing the grid[row][col]
syntax
Specs
tile_fun() :: (atom() -> IO.ANSI.Plus.ansidata())
Creates a tile from a cell value
Link to this section Functions
Specs
new() :: t()
Creates an "empty" grid.
Examples
iex> alias Islands.Grid
iex> grid = Grid.new()
iex> {grid[1][1], grid[10][10]}
{nil, nil}
iex> alias Islands.Grid
iex> grid = Grid.new()
iex> for row <- 1..10 do
iex> for col <- 1..10, uniq: true do
iex> grid[row][col]
iex> end
iex> end
[[nil], [nil], [nil], [nil], [nil], [nil], [nil], [nil], [nil], [nil]]
Specs
new(Islands.Board.t() | Islands.Guesses.t()) :: t()
Converts a board or guesses struct into a grid.
Specs
to_maps(Islands.Board.t() | Islands.Guesses.t(), tile_fun()) :: [map()]
Converts a board or guesses struct into a list of maps.