Portal Game v0.1.0 Portal.Door View Source
Using agents, portal doors maintain state.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Get the data currently in the door
.
Pops a value from the door
.
Pushes value
into the door.
Resets the door to []
Starts a door with the given color
.
Link to this section Functions
Link to this function
child_spec(arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor
.
Link to this function
get(door) View Source
Get the data currently in the door
.
Example
iex> Portal.Door.start_link(:rust)
iex> Portal.Door.push(:rust, 1)
iex> Portal.Door.get(:rust)
[1]
Link to this function
pop(door) View Source
Pops a value from the door
.
Returns {:ok, value}
if there is a value
or :error
if the portal is empty.
Example
iex> Portal.Door.start_link(:black)
iex> Portal.Door.pop(:black)
:error
iex> Portal.Door.start_link(:white)
iex> Portal.Door.push(:white, 1)
iex> Portal.Door.pop(:white)
{:ok, 1}
Link to this function
push(door, value) View Source
Pushes value
into the door.
Example
iex> Portal.Door.start_link(:pink)
iex> Portal.Door.push(:pink, 1)
:ok
Link to this function
reset(door) View Source
Resets the door to []
Example
iex> Portal.Door.start_link(:grey)
iex> Portal.Door.push(:grey, 1)
iex> Portal.Door.reset(:grey)
iex> Portal.Door.get(:grey)
[]
Link to this function
start_link(color) View Source
Starts a door with the given color
.
The color is given as a name so we can identify the door by color name instead of using a PID.
Example
iex> {:ok, pid} = Portal.Door.start_link(:yellow) # {:ok, #<PID<something.something.something>}
iex> is_pid(pid)
true