variable / @typed/fx

Push.filterMap

Maps each Fx output and emits only resulting Some values.

The upstream Sink evaluates f synchronously for each value, before its returned downstream callback Effect runs. Mapping allocation and throws occur at that callback invocation. Some(c) emits exactly one c; None emits nothing. Relative order, errors, services, and input behavior are preserved.

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

Import

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

Access Push.filterMap 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 filterMap: {
    <B, C>(f: (b: B) => Option.Option<C>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2, R2>;
    <A, E, R, B, E2, R2, C>(push: Push<A, E, R, B, E2, R2>, f: (b: B) => Option.Option<C>): Push<A, E, R, C, E2, R2>;
};

Why

Combine output parsing and filtering without a sentinel value or a second pass.

Ownership and lifetime

The mapper is synchronous at upstream onSuccess invocation and resource-free. The wrapped Fx retains ownership of subscription, Scope, interruption, and finalizers.

Examples

import { Effect, Option } 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", "x"]))
const numbers = Push.filterMap(push, (text) => /^\d+$/.test(text) ? Option.some(Number(text)) : Option.none())

Other public imports

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

Source