Documentation ¶
Overview ¶
Package fsm provides a basic finite state machine
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StateMachine ¶
type StateMachine[S comparable, I comparable] struct { States map[S]map[I]S // contains filtered or unexported fields }
StateMachine represents a state machine with states S and inputs I
func NewStateMachine ¶
func NewStateMachine[S comparable, I comparable](initialState S, States map[S]map[I]S) *StateMachine[S, I]
NewStateMachine creates a new state machine with states S and inputs I
func (*StateMachine[S, I]) AllowTransition ¶
func (sm *StateMachine[S, I]) AllowTransition(input I) bool
AllowTransition checks to see if the currentState has a transition identified by input
input -> takes the input verb
returns bool
func (*StateMachine[S, I]) CurrentState ¶
func (sm *StateMachine[S, I]) CurrentState() S
CurrentState returns the current state of the state machine
returns S
func (*StateMachine[S, I]) Transition ¶
func (sm *StateMachine[S, I]) Transition(input I)
Transition moves the state machine from the current state to the new state if the current state has input I
input -> takes the input verb
Click to show internal directories.
Click to hide internal directories.