variable / @typed/fx

Sink.filterMapLoop

Threads pure state through successes and optionally forwards a derived value.

Package version
2.0.0-beta.13
Category
Stateful delivery
Since
1.0.0
Member of
Sink

Import

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

Access Sink.filterMapLoop through the imported Sink export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

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

Why

It combines consumer-side state, filtering, and mapping in one ordered transition.

Ownership and lifetime

Each adapted sink owns its seed. Every input updates state synchronously; Some emits once and None emits nothing. Failures pass through. Reusing the sink continues from its retained seed; create a new sink to reset. The adapter acquires no resources.

Examples

import { Effect, Option } from "effect"
import * as Sink from "@typed/fx/Sink"
const target = Sink.make(Effect.logError, Effect.log)
const everyOther = Sink.filterMapLoop(target, false, (skip, n: number) => [skip ? Option.none() : Option.some(n), !skip])

Other public imports

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

Source