Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / bufferWhile

Function: bufferWhile()

bufferWhile<T>(predicate): Operator<T, T[]>

Defined in: projects/libraries/streamix/src/lib/operators/bufferWhile.ts:31

Buffers values while the provided predicate returns true.

The predicate is evaluated for each incoming value against the current buffer (before the value is added). If it resolves to true, the value is appended to the current buffer. If it resolves to false, the current buffer is flushed and a new buffer is started with the incoming value.

When the source completes, any remaining buffered values are emitted automatically.

Type Parameters

T

T = any

Source value type.

Parameters

predicate

(value, index, buffer) => MaybePromise<boolean>

Function invoked for each value to decide whether the value should remain in the current buffer. Receives the incoming value, the index, and the current buffer (before pushing the value). It may return a promise.

Returns

Operator<T, T[]>

Released under the MIT License.