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("input", () => configInput)
    .tap((input) => Console.log(`Validating ${input.label}`))
    .let("feature", (input) => ensureFlag(input.featureFlag))
    .let("throttle", (_, ctx) => ensureThrottle(ctx!["input"].throttle))
    .returnWith(({ input, feature, throttle }) => ({
      feature,
      throttle,
      label: input.label,
    }));

Awaiting execution

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

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