variable / @typed/fx

Sink.filterEffect

Runs an effectful predicate and forwards inputs for which it succeeds with true.

Package version
2.0.0-beta.13
Category
Selecting inputs
Since
1.0.0
Member of
Sink

Import

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

Access Sink.filterEffect 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 filterEffect: {
    <A, E2, R2>(f: (a: A) => Effect.Effect<boolean, E2, R2>): <E, R>(sink: Sink<A, E | E2, R>) => Sink<A, E | E2, R | R2>;
    <A, E, R>(sink: Sink<A, E, R>, f: (a: A) => Effect.Effect<boolean, E, R>): Sink<A, E, R>;
};

Why

A consumer can filter using service-backed or asynchronous policy without changing the producer.

Ownership and lifetime

Each input runs one predicate Effect. true forwards once, false not at all, and predicate failure reaches the sink’s failure callback. The producer controls callback ordering and concurrency; predicate services and interruption remain typed.

Examples

import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const positive = Sink.filterEffect(Sink.make(Effect.logError, Effect.log), (n: number) => Effect.succeed(n > 0))

Other public imports

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

Source