variable / @typed/fx

Push.filter

Keeps Fx output values that satisfy f.

The upstream Sink invokes the predicate synchronously for each output value, before the returned downstream callback Effect runs. Predicate allocation and throws therefore occur at upstream callback invocation. Matches preserve their relative order; non-matches produce no output. No buffer is added and every input callback is unchanged.

Package version
2.0.0-beta.7
Category
Selecting outputs
Since
1.0.0
Member of
Push

Import

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

Access Push.filter through the imported Push 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 filter: {
    <B>(f: (b: B) => boolean): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, B, E2, R2>;
    <A, E, R, B, E2, R2>(push: Push<A, E, R, B, E2, R2>, f: (b: B) => boolean): Push<A, E, R, B, E2, R2>;
};

Why

Restrict observed events without restricting which commands the Push accepts.

Ownership and lifetime

The predicate is synchronous at upstream onSuccess invocation and resource-free. Subscription, interruption, failures, services, and cleanup remain those of the wrapped Fx.

Examples

import { Effect } from "effect"
import * as Fx from "@typed/fx/Fx"
import * as Push from "@typed/fx/Push"
import * as Sink from "@typed/fx/Sink"

const push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), Fx.fromIterable([1, 2, 3]))
const even = Push.filter(push, (n) => n % 2 === 0)

Other public imports

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

Source