Program
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 };
});