View Source Islands.Grid (Islands Grid v0.1.27)
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
@type t() :: %{ required(Islands.Coord.row()) => %{required(Islands.Coord.col()) => atom()} }
A grid (map of maps) allowing the grid[row][col]
syntax
@type tile_fun() :: (atom() -> IO.ANSI.Plus.ansidata())
Creates a tile from a cell value
Link to this section Functions
@spec new() :: t()
Creates an "empty" grid.
examples
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]]
@spec new(Islands.Board.t() | Islands.Guesses.t()) :: t()
Converts a board or guesses struct into a grid.
@spec to_maps(Islands.Board.t() | Islands.Guesses.t(), tile_fun()) :: [map()]
Converts a board or guesses struct into a list of maps.