variable / @typed/fx/Sink

filterMapLoopCause

Threads pure state through failures and optionally forwards a transformed cause.

Package version
2.0.0-beta.13
Category
Stateful failure handling
Since
1.0.0

Import

import { filterMapLoopCause } from "@typed/fx/Sink";

Signatures

export declare const filterMapLoopCause: {
    <B, A, C>(seed: B, f: (acc: B, a: Cause.Cause<A>) => readonly [
        Option.Option<Cause.Cause<C>>,
        B
    ]): <E, R>(sink: Sink<A, C, R>) => Sink<A, E, R>;
    <A, E, R, B, C>(sink: Sink<A, C, R>, seed: B, f: (acc: B, a: Cause.Cause<E>) => readonly [
        Option.Option<Cause.Cause<C>>,
        B
    ]): Sink<A, E, R>;
};

Why

Stateful failure suppression and translation can be expressed without discarding Cause structure.

Ownership and lifetime

Each adapted sink owns its seed. Failure callbacks update state synchronously in invocation order; Some forwards once and None suppresses the failure. Successes pass through unchanged. Reusing the sink continues from its retained seed; create a new sink to reset.

Examples

import { Cause, Effect, Option } from "effect"
import * as Sink from "@typed/fx/Sink"
const target: Sink.Sink<number, string> = Sink.make(Effect.logError, Effect.log)
const first = Sink.filterMapLoopCause(target, true, (keep, cause: Cause.Cause<string>) => [keep ? Option.some(cause) : Option.none(), false])

Other public imports

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

Source