gen_state_machine_helpers v0.1.0 GenStateMachineHelpers
Helpers for GenStateMachine.
Replace those ugly return tuples with function calls.
The first argument is the data so they can be easily place in a pipeline.
For example:
def handle_event(:cast, {:add, num}, data) do
data
|> update_in([:num], & &1 + num)
|> keep_state
end
Link to this section Summary
Functions
Return the keep_state tuple
Return the keep_state tuple with a reply tuple
Return the next_state tuple
Return the next_state tuple with a reply tuple
Link to this section Functions
Return the keep_state tuple.
Examples
iex> GenStateMachineHelpers.keep_state(%{})
{:keep_state, %{}}
Return the keep_state tuple with a reply tuple.
Examples
iex> GenStateMachineHelpers.keep_state(%{}, [{:reply, :from, :result}])
{:keep_state, %{}, [{:reply, :from, :result}]}
Link to this function
next_state(data, state_name)
next_state(any, atom) :: {:next_state, atom, any}
Return the next_state tuple.
Examples
iex> GenStateMachineHelpers.next_state(%{}, :idle)
{:next_state, :idle, %{}}
Link to this function
next_state(data, state_name, reply)
next_state(any, atom, any) :: {:next_state, atom, any, any}
Return the next_state tuple with a reply tuple.
Examples
iex> GenStateMachineHelpers.next_state(%{}, :idle, [{:reply, :from, :result}])
{:next_state, :idle, %{}, [{:reply, :from, :result}]}