Skip to content

Instantly share code, notes, and snippets.

View jpmcglone's full-sized avatar

John P. McGlone jpmcglone

View GitHub Profile
@ValentinWalter
ValentinWalter / TextBuilder.swift
Created June 8, 2023 17:59
Build Text instances in a declarative manner, similar to regular views, from Text and Image. This ensures the font’s kerning, ligatures, and other properties are preserved across the entire text.
//
// TextBuilder.swift
//
//
// Created by Valentin Walter on 14.02.23.
//
import SwiftUI
/// Build Text instances in a declarative manner, similar to regular views, from
@andymatuschak
andymatuschak / States-v3.md
Last active June 12, 2024 04:17
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,