variable / @typed/fx/Push

filterMapInput

Transforms an input and forwards it only when f returns Some.

Calling onSuccess evaluates f immediately. Some(a) constructs one Sink callback Effect; None immediately returns an empty acknowledgment. Mapping allocation and throws therefore happen before the returned Effect runs. Calls are not serialized, so ordering follows the producer. Output is unchanged.

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

Import

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

Signatures

export declare const filterMapInput: {
    <C, A>(f: (c: C) => Option.Option<A>): <P extends Push.Any>(push: P) => Push<C, Sink.Error<P>, Sink.Services<P>, Fx.Fx.Success<P>, Fx.Fx.Error<P>, Fx.Fx.Services<P>>;
    <A, E, R, B, E2, R2, C>(push: Push<A, E, R, B, E2, R2>, f: (c: C) => Option.Option<A>): Push<C, E, R, B, E2, R2>;
};

Why

Option combines parsing and filtering without a sentinel value or a separate predicate pass.

Ownership and lifetime

The mapping is synchronous at onSuccess invocation and resource-free. A forwarded callback Effect retains the original Sink’s lifetime, error channel, and service requirements.

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 parsed: Array<string> = []
const integers = Push.filterMapInput(
  Push.make(Sink.make(() => Effect.void, (n: number) => Effect.log(n)), Fx.empty),
  (text: string) => {
    parsed.push(text)
    return /^\d+$/.test(text) ? Option.some(Number(text)) : Option.none()
  }
)
const acknowledgement = integers.onSuccess("nope")
// parsed is already ["nope"]; 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