Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1x 7x 14x 14x 2x 12x 12x 48x 48x 20x 20x 12x 6x | import {toSequence} from '../build';
import {Seq} from 'fnxt/fnxt-types';
export const chunkBySize = <E>(count: number) => (seq1: Seq<E>): Seq<E[]> =>
toSequence(function* () {
if (count <= 0) {
throw new Error('count must be greater then 0');
}
let arr = [];
for (const e of seq1) {
arr.push(e);
if (arr.length + 1 > count) { // +1 > to handle decimals
yield arr;
arr = [];
}
}
if (arr.length) {
yield arr;
}
});
|