Skip to content

Latest commit

 

History

History
34 lines (19 loc) · 1.91 KB

polyethylene.polyasynciterable.chunkwhile.md

File metadata and controls

34 lines (19 loc) · 1.91 KB

Home > polyethylene > PolyAsyncIterable > chunkWhile

PolyAsyncIterable.chunkWhile() method

Return an iteration of arrays with elements of this separated based on the result of calling func(elements).

Signature:

chunkWhile(func: AsyncChunkingPredicate<T>): PolyAsyncIterable<Array<T>>;

Parameters

Parameter Type Description
func AsyncChunkingPredicate<T> A function that decides if an element is part of the current chunk or initiates a new one

Returns:

PolyAsyncIterable<Array<T>>

A new PolyAsyncIterable that yields arrays with the elements of this as separated by func

Remarks

The chunking process works by keeping an open _current chunk_ and calling func to decide whether the next element of the iteration will be part of the _current chunk_ or if it will be part of a new chunk.

To do this, func will be called for every element of the iteration except the first, which will automatically become part of the first chunk. If func returns true, the element will be part of the current chunk, and if it returns false, the _current chunk_ is closed and the element becomes the first element if the new _current chunk_. The arguments passed to func will be, in order: - elem - The element being currently processed - lastElem - The last element that was added to the current chunk - firstElem - The first element of the current chunk (might be the same as lastElem)

All elements will be part of a chunk, and no chunk will ever be empty.