Split iterable into multiple chunks
splitIterable
const { splitIterable } = require('split-iterable')
expect(Array.from(
splitIterable([0, 'x', 1, 2, 'x', 3, 4, 5])
)).toEqual([
[0],
[1, 2],
[3, 4, 5]
])
splitAsyncIterable
const { splitAsyncIterable } = require('split-iterable')
const iterable = {
async * [Symbol.asyncIterator] () {
yield * [0, 'x', 1, 2, 'x', 3, 4, 5]
}
}
async function toArray (iterable) {
let array = []
for await (const item of iterable) {
array.push(item)
}
return array
}
expect(await toArray(
splitAsyncIterable(iterable)
)).toEqual([
[0],
[1, 2],
[3, 4, 5]
])
Generated using TypeDoc