Explores a pattern for structuring multi-step sequential programs in Go, inspired by Rob Pike's lexer state machine design. Each step is a method on a state struct that returns the next step function, using Go generics to enforce type safety between sequences. The approach enables independent unit testing of each step via runtime function name comparison, reduces verbose error-handling boilerplate, and supports custom step handlers for logging. The pattern is published as the open-source library lesiw.io/step.

9m read timeFrom lesiw.dev
Post cover image
Table of contents
Steps as functionsTypes as namespacesErrorsTesting transitionsPublishing solutions

Sort: