variable / @typed/fx/Versioned

map

Transform a Versioned’s output value as both an Fx and Effect.

Package version
2.0.0-beta.7
Category
Channel transformations
Since
1.18.0

Import

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

Signatures

export declare const map: {
    <A, E, R, C, B, D>(options: {
        onFx: (a: A) => C;
        onEffect: (b: B) => D;
    }): <R0, E0, R2, E2>(versioned: Versioned<R0, E0, A, E, R, B, E2, R2>) => Versioned<never, never, C, E, R, D, E0 | E2, R0 | R2>;
    <R0, E0, A, E, R, B, E2, R2, C, D>(versioned: Versioned<R0, E0, A, E, R, B, E2, R2>, options: {
        onFx: (a: A) => C;
        onEffect: (b: B) => D;
    }): Versioned<never, never, C, E, R, D, E0 | E2, R0 | R2>;
};

Why

Applies corresponding pure projections to pushed and sampled values while leaving the version token unchanged.

Ownership and lifetime

map does not take ownership of its inputs. Its observation and current-read channels retain upstream lifetime, typed failures, services, and interruption behavior.

Pure callbacks preserve push order and cardinality. onFx applies to every pushed update; onEffect applies only when the current value is sampled.

Examples

import { Effect } from "effect"
import * as Versioned from "@typed/fx/Versioned"

const length = Versioned.map(Versioned.of("typed"), {
  onFx: (value) => value.length,
  onEffect: (value) => value.length
})

const currentLength = Effect.runPromise(length)

Other public imports

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

Source