GraphReFlyTS

API Reference

reduce()

reduce: accumulate over the whole source, emit ONE final value on the source's COMPLETE (RxJS reduce). Unlike {@link scan} (which emits every step), reduce stays quiet until the source terminates. completeWhenDepsComplete:false + terminalAsRealInput:true: the fn fires on the source COMPLETE (reading terminal===true) and emits the accumulator + COMPLETE. An empty source emits the seed (RxJS parity). A source ERROR auto-forwards (errorWhenDepsError default).

Import

import { reduce } from "@graphrefly/ts/operators";

Signature

function reduce(
	reducer: (acc: T, v: S) => T,
	seed: T,
): Operator<S, T>

Parameters

ParameterTypeDescription
reducer(acc: T, v: S) => TReducer called with the accumulator and each upstream DATA value.
seedTInitial accumulator value emitted if the source completes empty.

Returns

An operator that emits one accumulated value when the source completes.

Example

import { graph } from "@graphrefly/ts/graph";
import { reduce } from "@graphrefly/ts/operators";

const total = graph().initNode(reduce((sum: number, value: number) => sum + value, 0), [source]);

Source

packages/ts/src/graph/operators.ts