fsm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fsm provides generic helpers for map-based finite-state-machine transition tables used by kernel state machines. A transition table maps each state to the states reachable from it. A terminal state has no outgoing edges: it may be either absent from the table (lookup miss → nil slice) or present with an explicit empty slice — both deny all transitions identically (slices.Contains over nil and []S{} is false). kernel/outbox uses the explicit-empty-key form so OUTBOX-STATE-TRANSITION-COMPLETENESS-01 can require every State const to be a key; kernel/saga uses the absent form. Either is valid.

kernel/saga uses these helpers. kernel/command predates this package and still inlines the same lookup/defensive-copy bodies; migrating it is a candidate cleanup (it must be done without dropping command below the 90% kernel coverage gate, since the removed lines are fully covered). Tracked in gh issue #936.

The helpers are intentionally tiny and type-agnostic: per-state-machine concerns — the Status enum, its String/Valid/IsTerminal methods, and the package-specific Transition error message — stay in the owning package. This removes the duplicated lookup/defensive-copy boilerplate without flattening the distinct state machines into one type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedTargets

func AllowedTargets[S comparable](table map[S][]S, from S) []S

AllowedTargets returns a defensive copy of the states reachable from `from`, or nil when there are none (terminal or unknown state). Mutating the result does not affect table.

func CanTransition

func CanTransition[S comparable](table map[S][]S, from, to S) bool

CanTransition reports whether table permits a transition from → to. A state with no outgoing edges (absent from table, or present with an empty slice — e.g. a terminal state) permits no transitions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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