Effects as data.
The ocpp/protocol machines never perform IO. Each update returns an
Effect(out) — an ordered collection of output values describing what the
caller should do (write a string to the socket, deliver a response to the
application, report a violation). Adapters and tests read the outputs with
to_list and interpret them however they like; nothing here is a closure,
so effects can be logged, compared, and replayed.
An ordered batch of outputs produced by a state-machine transition.
Opaque so the representation can change (and so callers go through
to_list rather than pattern matching), but semantically it is just the
list of outputs in the order they were emitted.
pub opaque type Effect(out)
pub fn batch(effects: List(Effect(out))) -> Effect(out)
Combine effects, preserving order: all outputs of the first effect come
before all outputs of the second, and so on.
pub fn emit(output: out) -> Effect(out)
An effect carrying a single output.
pub fn map(fx: Effect(a), f: fn(a) -> b) -> Effect(b)
Transform every output in the effect. Used by wrapping machines (station,
CSMS) to lift inner-machine outputs into their own output type.
pub fn none() -> Effect(out)
The empty effect: this transition asks nothing of the caller.
pub fn to_list(fx: Effect(out)) -> List(out)
Extract the outputs, in emission order, for the caller to interpret.