Skip to content

Instantly share code, notes, and snippets.

View ar-nelson's full-sized avatar

Adam R. Nelson ar-nelson

View GitHub Profile
@Ph0enixKM
Ph0enixKM / color.cpp
Last active July 8, 2023 11:33
Cross Platform Terminal Color Output Library (Windows/Linux/Mac)
// Color Terminal Output Library
// MIT Licensed Library
// There are 6 colors:
//
// blue
// green
// cyan
// red
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,