variable / @typed/fx

Push.filterInput

Keeps successful inputs that satisfy f and discards the rest.

Calling onSuccess runs the predicate immediately. A match constructs one Sink callback Effect; a non-match immediately returns an empty acknowledgment. Predicate allocation and throws therefore occur before the returned Effect is run. The producer controls call order and concurrency; output is preserved.

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

Import

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

Access Push.filterInput 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 filterInput: {
    <A>(f: (a: A) => boolean): <E, R, B, 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: (a: A) => boolean): Push<A, E, R, B, E2, R2>;
};

Why

Filtering before the consumer avoids teaching the underlying Sink about input values that are irrelevant to it.

Ownership and lifetime

The predicate is synchronous at onSuccess invocation and acquires no resources. Accepted callback Effects retain the original Sink’s errors, services, interruption, and cleanup.

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 checks: Array<number> = []
const positives = Push.filterInput(
  Push.make(Sink.make(() => Effect.void, (n: number) => Effect.log(n)), Fx.empty),
  (n) => (checks.push(n), n > 0)
)
const acknowledgement = positives.onSuccess(-1)
// checks is already [-1]; acknowledgement performs no Sink callback.

Other public imports

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

Source