group or chunk
jangchoe opened this issue · comments
jangchoe commented
Do you have plans to have a group
or chunk
function? Something like:
async function* generator() {
yield* [1, 2, 3, 4, 5, 6, 7];
}
(async function () {
const q = await itiririAsync(generator()).chunk(3).awaitAll();
q.toArray(); // returns [[1,2,3],[4, 5, 6],[7]]
})();
Dumitru commented
Not for async iterables. Grouping a collection requires to know in advance the elements. You can instead await the async iterable then use the itiriri's sync groupBy
method to achieve this:
(async function () {
const q = (await itiririAsync(generator()).awaitAll()).groubBy((_, i) => Math.floor(i / 3));
q.toArray(); // returns [[1,2,3],[4, 5, 6],[7]]
})();