function / @typed/fx/Sink

filterMapLoopCauseEffect

Threads state through an effectful failure transition and optionally forwards a cause.

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

Import

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

Signatures

export declare function filterMapLoopCauseEffect<A, E, R, B, E2, R2, C>(sink: Sink<A, E2 | C, R>, seed: B, f: (acc: B, a: Cause.Cause<E>) => Effect.Effect<readonly [
    Option.Option<Cause.Cause<C>>,
    B
], E2, R2>): Sink<A, E, R | R2>;

Why

It supports service-backed, stateful failure suppression or translation at the consumer boundary.

Ownership and lifetime

Callback invocation constructs a transition Effect from the seed visible at that moment. The adapter does not serialize those Effects: overlapping failures can read the same seed, and successful transitions commit in completion order. Some forwards one cause, None suppresses it, and transition failure is forwarded without committing. Successes pass through. The sink instance retains its seed across producer runs; construct a new one to reset it.

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 sink = Sink.filterMapLoopCauseEffect(target, false, (seen, cause: Cause.Cause<string>) =>
  Effect.succeed([seen ? Option.none() : Option.some(cause), true] as const))

Other public imports

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

Source