gwi/dict_world
Types
A display dict world instruction.
pub opaque type Instruction(position, state, effect)
Values
pub fn delete(
in world: DictWorld(position, state, effect),
delete position: position,
effect effect: effect,
) -> DictWorld(position, state, effect)
Deletes an object in the dict world with the given postion.
pub fn delete_to(
in world: DictWorld(position, state, effect),
from from_position: position,
to to_position: position,
effect effect: effect,
) -> DictWorld(position, state, effect)
Deletes an object in the dict world from a postion to another postion.
pub fn flush(
world: DictWorld(position, state, effect),
) -> DictWorld(position, state, effect)
Return a flushed dict world.
pub fn from_dict(
dict: dict.Dict(position, #(state, effect)),
) -> DictWorld(position, state, effect)
Converts a Dict(position, #(state, effect)) to a
DictWorld(position, state, effect).
pub fn get(
world: DictWorld(position, state, effect),
get position: position,
) -> Result(state, Nil)
Fetches an object from a dict world for a given position.
pub fn has_position(
world: DictWorld(position, state, effect),
position: position,
) -> Bool
Determines whether or not a value present in the dict world for a given position.
pub fn instruction_to_json(
instruction: Instruction(position, state, effect),
position_encoder: fn(position) -> json.Json,
state_encoder: fn(state) -> json.Json,
effect_encoder: fn(effect) -> json.Json,
) -> json.Json
Encode a display dict world instruction into a JSON object.
pub fn is_empty(
world: DictWorld(position, state, effect),
) -> Bool
Determines whether or not the dict world is empty.
pub fn move(
in world: DictWorld(position, state, effect),
from from_position: position,
to to_position: position,
effect effect: effect,
) -> Result(DictWorld(position, state, effect), Nil)
Moves an object in the dict world from a postion to another postion.
pub fn new() -> DictWorld(position, state, effect)
Creates a fresh dict world that contains no objects.
pub fn positions(
world: DictWorld(position, state, effect),
) -> List(position)
Gets a list of all positions in a given dict world.
The world are not ordered so the positions are not returned in any specific order. Do not write code that relies on the order positions are returned by this function as it may change in later versions of Gleam or Erlang.
pub fn size(world: DictWorld(position, state, effect)) -> Int
Determines the number of objects in the dict world.
pub fn spawn(
in world: DictWorld(position, state, effect),
for position: position,
state state: state,
effect effect: effect,
) -> Result(DictWorld(position, state, effect), Nil)
Spawns an object in the dict world with the given postion.
pub fn spawn_from(
in world: DictWorld(position, state, effect),
from from_position: position,
to to_position: position,
state state: state,
effect effect: effect,
) -> Result(DictWorld(position, state, effect), Nil)
Spawns an object in the dict world from a postion to another postion.
pub fn states(
world: DictWorld(position, state, effect),
) -> List(state)
Gets a list of all states in a given dict.
The world are not ordered so the states are not returned in any specific order. Do not write code that relies on the order states are returned by this function as it may change in later versions of Gleam or Erlang.
pub fn swap(
in world: DictWorld(position, state, effect),
positions positions: List(#(position, effect)),
) -> Result(DictWorld(position, state, effect), Nil)
Swapes postion of multiple objects in the dict world.
pub fn swap_update(
in world: DictWorld(position, state, effect),
positions positions: List(
#(position, fn(state) -> #(state, effect)),
),
) -> Result(DictWorld(position, state, effect), Nil)
Swapes postion and updates multiple objects in the dict world.
pub fn to_dict(
world: DictWorld(position, state, effect),
) -> dict.Dict(position, state)
Converts a DictWorld(position, state, effect) to a
Dict(position, state).
pub fn to_instruction(
world: DictWorld(position, state, effect),
with fun: fn(position, state) -> view,
) -> Instruction(position, view, effect)
Convert a dict world to a display dict world instruction.
pub fn transit(
in world: DictWorld(position, state, effect),
from from_position: position,
to to_position: position,
with fun: fn(state) -> #(state, effect),
) -> Result(DictWorld(position, state, effect), Nil)
Moves an object in the dict world from a postion to another postion, and update its state using a given function.