Skip to content
PACKAGES

map()

Transform each upstream DATA value with a synchronous mapping function.

import { map } from "@graphrefly/ts/operators";
function map(fn: ((v: S) => T) | Definition<S, T>): Operator<S, T>
ParameterTypeDescription
fn((v: S) => T) | Definition<S, T>Mapping function, or a named define() definition for checkpoint restoration.

An operator that emits fn(value) for each upstream value.

import { graph } from "@graphrefly/ts/graph";
import { map } from "@graphrefly/ts/operators";
const g = graph();
const count = g.state(1);
const doubled = g.initNode(map((value: number) => value * 2), [count]);
  • Restorable maps: Passing a named define() registers semantic restore metadata.

packages/ts/src/graph/operators.ts