Skip to content
Buy me a coffee

Gatherers

const Gatherers: object

Defined in: src/stream/Gatherers.ts:304

Built-in Gatherers for stream.gather. All are sequential (default combiner).

fold<T, R>(initial, folder): DefinedGatherer<T, Acc<R>, R>

Returns a gatherer that folds the elements, in order, into one value starting from initial() and emits it at the end of input; an empty stream emits initial().

T

R

() => R

(acc, element) => R

DefinedGatherer<T, Acc<R>, R>

NullPointerException if initial or folder is null

mapConcurrent<T, R>(maxConcurrency, mapper): DefinedGatherer<T, null, R>

Returns a gatherer that maps each element, preserving encounter order. The mapper runs synchronously, one element at a time; maxConcurrency is validated but has no further effect. A mapper exception is rethrown as-is when it is a RuntimeException, otherwise wrapped in a RuntimeException with it as cause. The mapper is not called once the downstream is rejecting. Promises are not awaited.

T

R

number

(element) => R

DefinedGatherer<T, null, R>

IllegalArgumentException if maxConcurrency is less than 1 (or not an integer)

NullPointerException if mapper is null

scan<T, R>(initial, scanner): DefinedGatherer<T, Acc<R>, R>

Returns a gatherer that emits every running accumulation: scanner(current, element) for each element, starting from initial() (which itself is not emitted).

T

R

() => R

(acc, element) => R

DefinedGatherer<T, Acc<R>, R>

NullPointerException if initial or scanner is null

windowFixed<T>(windowSize): DefinedGatherer<T, Window<T>, List<T>>

Returns a gatherer that groups elements into consecutive unmodifiable lists of windowSize; the last window may be shorter. No window for empty input.

T

number

DefinedGatherer<T, Window<T>, List<T>>

IllegalArgumentException if windowSize is less than 1 (or not an integer)

windowSliding<T>(windowSize): DefinedGatherer<T, Window<T>, List<T>>

Returns a gatherer of sliding unmodifiable windows of windowSize, each dropping the oldest element of the previous one. With fewer elements than windowSize, one window holding all of them; none for empty input.

T

number

DefinedGatherer<T, Window<T>, List<T>>

IllegalArgumentException if windowSize is less than 1 (or not an integer)