map()
Transform each upstream DATA value with a synchronous mapping function.
Import
Section titled “Import”import { map } from "@graphrefly/ts/operators";Signature
Section titled “Signature”function map(fn: ((v: S) => T) | Definition<S, T>): Operator<S, T>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fn | ((v: S) => T) | Definition<S, T> | Mapping function, or a named define() definition for checkpoint restoration. |
Returns
Section titled “Returns”An operator that emits fn(value) for each upstream value.
Example
Section titled “Example”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]);Remarks
Section titled “Remarks”- Restorable maps: Passing a named
define()registers semantic restore metadata.
Source
Section titled “Source”packages/ts/src/graph/operators.ts