Modern finite-state machine implemented in pure Swift