Skip to content
docsv0.1.0

Reducer

Folds a process instance's events into its current {@see ProcessState}. Pure: given the same events and the same definition it always returns the same state — no I/O, no mutable state of its own. This is the mechanism behind "state is a projection of the log": nothing in the orchestrator stores `current_state` directly, everything asks the reducer to derive it.

Reducer::apply()

public function apply(array $events, Milpa\Orchestrator\DefinitionContract $definition): Milpa\Orchestrator\ProcessState

Starts at `$definition->initialState()` and, for every event in order, looks up the transitions available from the current state and advances to the one whose `name` equals the event's `type`. An event that matches no available transition leaves the state unchanged. Every event's `payload` is merged into the accumulated context regardless of whether it matched a transition, so bootstrap/audit events (e.g. `ProcessStarted`) can carry context without needing a transition of their own.

Parameters

Parameters of apply()
NameTypeDescription
$eventslist<Event>in the order they should be folded (ascending `seq`)
$definitionMilpa\Orchestrator\DefinitionContract