variable / @typed/guard

catchCause

Recovers from the complete Effect Cause and lifts the recovery result into Some.

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

Import

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

Signatures

export declare const catchCause: {
    <E, O2, E2, R2>(f: (e: Cause.Cause<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: Cause.Cause<E>) => Effect.Effect<O2, E2, R2>): Guard<I, O | O2, E2, R | R2>;
};

Why

Cause-aware recovery can deliberately handle typed failures, defects, and interruption; None remains an unrecovered non-match.

Ownership and lifetime

Construction acquires no resources; recovery starts only when the source Effect fails and follows that invocation’s lifetime.

Examples

import { catchCause } 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 = catchCause(source, () => Effect.succeed("fallback"))

Source