Pure Workflow Sequencing

State + Console + Exception with seq()

Why it matters

  • `seq()` advances workflow state while keeping data immutable.
  • Console + Exception handlers yield audit trails automatically.
seq()StateConsolematch()pipe() Console.capture()State.with()Exception.tryCatch() Workflow state
Program
// Multi-capability type alias: record-based effect composition
// Order-independent, self-documenting
type WorkflowCaps = Readonly<{
  console: typeof Console.spec;
  state: ReturnType<typeof State.spec<WorkflowState>>;
  exception: typeof Exception.spec;
}>;

const workflow = (): Eff<WorkflowSnapshot, WorkflowCaps> =>
  seq()
    .let("state", () => State.get<WorkflowState>())
    .then((state) => state.stage)
    .then((stage) => nextStage(stage))
    .let("next", (next) => next)
    .then((next) => ({ stage: next, note: stageNote(next) }))
    .let("event", (event) => event)
    .tap((event) => Console.log(`Stage → ${stageLabel(event.stage)}`))
    .tapWith(({ state, event }) => {
      const history = appendEvent(state.history, event);
      return State.put({ stage: event.stage, history });
    })
    .returnWith(({ state, event }) => {
      const history = appendEvent(state.history, event);
      return { stage: event.stage, history };
    });

Awaiting execution

Console output, timeline events and workflow state snapshots will render here after you run the program.

Handlers: Console.capture() · State.with() · Exception.tryCatch()