bufferize()
bufferize<
T,R>(options):OperatorFunction<T,R>
Defined in: src/Bufferize.ts:50
Creates an operator that accumulates incoming items into a value and emits
it when shouldFlush returns true, when timeFrame elapses, or when the
source ends. batch and interval are built on it.
Whatever is left in the accumulator when the source ends is emitted as a
last value. If the source, the reducer or shouldFlush throws, the items
accumulated so far are emitted first as a last, smaller value, and then the
error is thrown to the consumer.
Type Parameters
T
T
R
R
Parameters
options
BufferizeOptions<T, R>
see BufferizeOptions
Returns
OperatorFunction<T, R>
an operator function
Example
const sums = await chain([1, 2, 3, 4, 5])
.bufferize({
getInitialValue: () => 0,
reducer: (acc: number, value: number) => acc + value,
shouldFlush: (_acc, _value, count) => count >= 2,
})
.toArray();
// => [3, 7, 5]