Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / reduce

Function: reduce()

reduce<T, A>(accumulator, seed): Operator<T, A>

Defined in: projects/libraries/streamix/src/lib/operators/reduce.ts:17

Creates a stream operator that accumulates all values from the source stream into a single value using a provided accumulator function.

This operator consumes the source lazily and emits intermediate values as phantoms. It will always emit at least the seed value if the stream is empty.

Type Parameters

T

T = any

The type of the values in the source stream.

A

A = any

The type of the accumulated value.

Parameters

accumulator

(acc, value) => MaybePromise<A>

Function combining current accumulated value with a new value. Can be synchronous or asynchronous.

seed

A

Initial value for the accumulator.

Returns

Operator<T, A>

An Operator instance usable in a stream's pipe method.

Released under the MIT License.