state_server v0.4.10 StateServer.StateGraph View Source

tools for dealing with stategraphs.

State graphs take the form of a keyword list of keyword lists, wherein the outer list is a comprehensive list of the states, and the inner lists are keywords list of all the transitions, with the values of the keyword list as the destination states.

Link to this section Summary

Functions

lists all state/transition pairs. Used to generate the StateServer.is_transition/2 guard.

converts a list of atoms to a type which is the union of the atom literals

outputs a list of edges of the graph. Used to generate the StateServer.is_transition/3 guard.

returns the starting state from the state graph.

lists all states in the state graph. The first element in this list will always be the initial state.

outputs a list of terminal states of the graph. Used to generate the StateServer.is_terminal/1 guard.

outputs a list of terminal {state, transition} tuples of the graph. Used to generate the StateServer.is_terminal/2 guard.

outputs the destination state given a source state and a transition.

lists all transitions in the state graph.

lists all transitions emanating from a given state.

checks the validity of the state graph.

Link to this section Types

Link to this section Functions

Link to this function

all_transitions(stategraph)

View Source
all_transitions(t()) :: keyword()

lists all state/transition pairs. Used to generate the StateServer.is_transition/2 guard.

Example

iex> StateServer.StateGraph.all_transitions([start: [t1: :state1, t2: :state2], state1: [], state2: [t2: :state1]])
[start: :t1, start: :t2, state2: :t2]
Link to this function

atoms_to_typelist(list)

View Source
atoms_to_typelist([atom()]) :: Macro.t()

converts a list of atoms to a type which is the union of the atom literals

Link to this function

edges(state_graph)

View Source
edges(t()) :: keyword({atom(), atom()})

outputs a list of edges of the graph. Used to generate the StateServer.is_transition/3 guard.

iex> StateServer.StateGraph.edges(start: [t1: :state1, t2: :state2], state1: [t3: :start], state2: [])
[start: {:t1, :state1}, start: {:t2, :state2}, state1: {:t3, :start}]

returns the starting state from the state graph.

iex> StateServer.StateGraph.start([start: [t1: :state1], state1: [t2: :state2], state2: []])
:start
Link to this function

states(stategraph)

View Source
states(t()) :: [atom()]

lists all states in the state graph. The first element in this list will always be the initial state.

Example

iex> StateServer.StateGraph.states([start: [t1: :state1], state1: [t2: :state2], state2: [t2: :state2]])
[:start, :state1, :state2]
Link to this function

terminal_states(stategraph)

View Source
terminal_states(t()) :: [atom()]

outputs a list of terminal states of the graph. Used to generate the StateServer.is_terminal/1 guard.

iex> StateServer.StateGraph.terminal_states(start: [t1: :state1, t2: :state2], state1: [], state2: [])
[:state1, :state2]
Link to this function

terminal_transitions(stategraph)

View Source
terminal_transitions(t()) :: keyword(atom())

outputs a list of terminal {state, transition} tuples of the graph. Used to generate the StateServer.is_terminal/2 guard.

iex> StateServer.StateGraph.terminal_transitions(start: [t1: :state1, t2: :state2], state1: [], state2: [])
[start: :t1, start: :t2]
Link to this function

transition(stategraph, start, transition)

View Source
transition(t(), start :: atom(), transition :: atom()) :: atom()

outputs the destination state given a source state and a transition.

Example

iex> StateServer.StateGraph.transition([start: [t1: :state1, t2: :state2], state1: [], state2: []], :start, :t1)
:state1
Link to this function

transitions(stategraph)

View Source
transitions(t()) :: [atom()]

lists all transitions in the state graph.

Example

iex> StateServer.StateGraph.transitions([start: [t1: :state1], state1: [t2: :state2], state2: [t2: :state2]])
[:t1, :t2]
Link to this function

transitions(stategraph, state)

View Source
transitions(t(), atom()) :: [atom()]

lists all transitions emanating from a given state.

Example

iex> StateServer.StateGraph.transitions([start: [t1: :state1, t2: :state2], state1: [], state2: []], :start)
[:t1, :t2]
Link to this function

valid?(stategraph)

View Source
valid?(t()) :: boolean()

checks the validity of the state graph.

Should only be called when we build the state graph.

A state graph is valid if and only if all of the following are true:

  1. the graph is a keyword of keywords.
  2. there is at least one state.
  3. there are no duplicate state definitions.
  4. there are no duplicate transition definitions emanating from any given state.
  5. all of the destinations of the transitions are states.