scan()
Accumulate upstream values and emit each intermediate accumulator.
Import
Section titled “Import”import { scan } from "@graphrefly/ts/operators";Signature
Section titled “Signature”function scan( reducer: (acc: T, v: S) => T, seed: T,): Operator<S, T>Parameters
Section titled “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
Section titled “Returns”An operator that emits the accumulator after every input value.
Example
Section titled “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
Section titled “Source”packages/ts/src/graph/operators.ts