Typed Exception Guards

Total validation with match() + Exception

Why it matters

  • `match()` replaces `if`/`else` for total validation paths.
  • Exception handlers return typed errors instead of thrown exceptions.
Exceptionmatch()seq()Console Console.capture()Exception.tryCatch()
Program
// Multi-capability type: validation with logging and error handling
// Demonstrates record-based capabilities for clean composition
type ConfigProgramCaps = Readonly<{
  console: typeof Console.spec;
  exception: typeof Exception.spec;
}>;

const config = (): Eff<ConfigSnapshot, ConfigProgramCaps> =>
  seq()
    .let(() => configInput) // ctx.v1
    .tap((input) => Console.op.log(`Validating ${input.label}`))
    .let((input) => ensureFlag(input.featureFlag)) // ctx.v2
    .let((_, ctx) => ensureThrottle((ctx!["v1"] as ConfigInput).throttle)) // ctx.v3
    .return((throttle, ctx) => ({
      feature: ctx!["v2"] as FeatureMode,
      throttle,
      label: (ctx!["v1"] as ConfigInput).label,
    }));

Awaiting execution

Console output, timeline events will render here after you run the program.

Handlers: Console.capture() ยท Exception.tryCatch()