UNPKG

518 BJavaScriptView Raw
1const END = Number.MAX_SAFE_INTEGER;
2function* cutAt(x, is) {
3 var ii = is[Symbol.iterator]();
4 var { value, done } = ii.next();
5 if (done)
6 value = END;
7 var a = [], j = -1;
8 for (var v of x) {
9 if (++j < value) {
10 a.push(v);
11 continue;
12 }
13 yield a;
14 a = [v];
15 var { value, done } = ii.next();
16 if (done)
17 value = END;
18 }
19 yield a;
20 for (; !done; { done } = ii.next())
21 yield [];
22}
23export default cutAt;