Skip to content

asyncChunk

asyncChunk<T>(xs, size): AsyncIterable<T[]>

Creates an async generator that splits the given AsyncIterable into chunks of the required size. If no even chunks can be created, the last chunk will have fewer elements.

Example

await asyncCollect(asyncChunk([1, 2, 3, 4, 5], 1))
// => [[1], [2], [3], [4], [5]]
await asyncCollect(asyncChunk([1, 2, 3, 4, 5], 3))
// => [[1, 2, 3], [4, 5]]
await asyncCollect(asyncChunk([1, 2, 3], 0))
// => [[1], [2], [3]]

Type Parameters

T

The element type.

Parameters

xs

The values to split in chunks.

AsyncIterable<T> | Iterable<T>

size

number

Returns

AsyncIterable<T[]>

An async map generator.

See

chunk