variable / @typed/guard

catchAll

Recovers typed failures and lifts the recovery result into Some.

Package version
1.0.0-beta.13
Category
Error recovery
Since
1.0.0

Import

import { catchAll } from "@typed/guard";

Signatures

export declare const catchAll: {
    <E, O2, E2, R2>(f: (e: E) => Effect.Effect<O2, E2, R2>): <I, O, R>(guard: GuardInput<I, O, E, R>) => Guard<I, O | O2, E2, R | R2>;
    <I, O, E, R, O2, E2, R2>(guard: GuardInput<I, O, E, R>, f: (e: E) => Effect.Effect<O2, E2, R2>): Guard<I, O | O2, E2, R | R2>;
};

Why

Typed recovery leaves defects and interruption untouched and does not confuse successful None with failure. The exported catch name is an alias of this declaration.

Ownership and lifetime

Construction acquires no resources; recovery starts only for typed failure during the source invocation.

Examples

import { catchAll } from "@typed/guard"
import type { Guard } from "@typed/guard"
import { Effect } from "effect"
const source: Guard<string, string, string> = (input) => input ? Effect.succeedSome(input) : Effect.fail("empty")
const recovered = catchAll(source, (error) => Effect.succeed(error.length))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source