fsm

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 0 Imported by: 0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL