Skip to content
PACKAGES

scan()

Accumulate upstream values and emit each intermediate accumulator.

import { scan } from "@graphrefly/ts/operators";
function scan(
reducer: (acc: T, v: S) => T,
seed: T,
): Operator<S, T>
ParameterTypeDescription
reducer(acc: T, v: S) => TReducer called with the previous accumulator and each upstream value.
seedTInitial accumulator value.

An operator that emits the accumulator after every input value.

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]);

packages/ts/src/graph/operators.ts