Package-level declarations
Types
Receiver scope of program blocks: sequence sub-programs, and effects, with bind. Suspension is restricted, so only binds — not arbitrary suspend calls — can occur inside.
Functions
Interpret with auto-resume: the block's return value is the effect's response. For an effect that returns Unit, do the work; for one that returns a value, return it. The block may bind other programs, which run in place of the effect as in a program block, so a rule that translates its effect into I/O binds a performIO { }. The block is a one-shot coroutine: under a multi-shot handler such as collectAll, a block that binds the choice fails when resumed a second time, while one that returns without suspending is fine.
Stateful handle: the block receives the current state and returns newState to response. Mind the pair order when the state and the response share a type — response to newState is equally well-typed and silently swaps the two. The state is threaded by value, so each interpretation starts from initialState and shares nothing with another; a rule that mutates the initial state in place instead of returning a new one shares it between every interpretation of the program.
Middleware: observe an effect without consuming it. proceed() re-emits the effect to the handler downstream and returns its response, so the rule decides where the effect executes and may inspect, rewrite or replace the result; a rule that answers without calling proceed() consumes the effect. Effects the rule performs itself are seen only by the handlers applied after this one, so a middleware that logs needs the log handler downstream of it.
Handle and remove every effect of family E. rule receives the effect and a resume continuation: resume(response) is the rest of the program with response as the effect's result, as a program that nothing has run yet. Return it to continue, transform it with flatMap or map or bind it in a program { } block to work on the rest's result, call it more than once to resume the same continuation more than once, or leave it uncalled to cut the program short. Every form runs on a constant stack. Applied lazily, when the program is run.
Handle and remove every effect of family E, mapping the final value with transformDone. rule receives the effect and a resume continuation: resume(response) is the rest of the program with response as the effect's result, as a program that nothing has run yet. Return it to continue, transform it with flatMap or map or bind it in a program { } block to work on the rest's result, call it more than once to resume the same continuation more than once, or leave it uncalled to cut the program short. Every form runs on a constant stack. Applied lazily, when the program is run.
Handle and remove every effect of family E, threading state S from initialState; resume takes the next state and the response, and is the rest of the program as in interpret, with the same forms and the same lazy application.
Handle and remove every effect of family E, threading state S from initialState through every step; transformDone sees the final state and value. resume takes the next state and the response, and is the rest of the program as in interpret, with the same forms and the same lazy application.
Build a Program in direct style: .bind() each sub-program, or each effect, instead of chaining flatMap. The block is captured, not run — each interpretation forces it afresh, so program{} values are pure, replayable descriptions that can be interpreted any number of times, under different handler stacks.
Extract the final value of a fully handled program, or throw naming the unhandled effect.