variable / @typed/fx/Push

map

Synchronously transforms every value emitted by the Fx output side.

It emits exactly one C for every upstream B, preserving order and the complete input Sink. The mapping does not buffer or introduce concurrency.

Package version
2.0.0-beta.13
Category
Transforming outputs
Since
1.0.0

Import

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

Signatures

export declare const map: {
    <B, C>(f: (b: B) => 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) => C): Push<A, E, R, C, E2, R2>;
};

Why

Adapt observed events without changing the commands the bidirectional boundary accepts.

Ownership and lifetime

f runs in the upstream Fx delivery path and owns no resource. Output subscription, interruption, failures, services, and cleanup remain those of the wrapped Fx and downstream Sink.

Examples

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

const program = Effect.gen(function* () {
  const push = Push.make(
    Sink.make(
      (cause) => Effect.void,
      (value) => Effect.void
    ),
    Fx.succeed(42)
  )

  // Map output from number to string
  const mapped = Push.map(push, (n) => `Number: ${n}`)

  // Observe the mapped output
  yield* Fx.observe(mapped, (value) =>
    Effect.sync(() => console.log(value))
  )
  // Output: "Number: 42"
})

Other public imports

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

Source