API Reference
scan()
Accumulate upstream values and emit each intermediate accumulator.
Import
import { scan } from "@graphrefly/ts/operators";
Signature
function scan(
reducer: (acc: T, v: S) => T,
seed: T,
): Operator<S, T>
Parameters
| Parameter | Type | Description |
|---|---|---|
reducer | (acc: T, v: S) => T | Reducer called with the previous accumulator and each upstream value. |
seed | T | Initial accumulator value. |
Returns
An operator that emits the accumulator after every input value.
Example
import { graph } from "@graphrefly/ts/graph";
import { scan } from "@graphrefly/ts/operators";
const g = graph();
const values = g.state(1);
const total = g.initNode(scan((sum: number, value: number) => sum + value, 0), [values]);
Source
packages/ts/src/graph/operators.ts