UNPKG

866 BJavaScriptView Raw
1import { AsyncIterableX } from './asynciterablex';
2export class SliceAsyncIterable extends AsyncIterableX {
3 constructor(source, begin, end) {
4 super();
5 this._source = source;
6 this._begin = begin;
7 this._end = end;
8 }
9 async *[Symbol.asyncIterator]() {
10 let it = this._source[Symbol.asyncIterator](), begin = this._begin, next;
11 while (begin > 0 && !(next = await it.next()).done) {
12 begin--;
13 }
14 let end = this._end;
15 if (end > 0) {
16 while (!(next = await it.next()).done) {
17 yield next.value;
18 if (--end === 0) {
19 break;
20 }
21 }
22 }
23 }
24}
25export function slice(source, begin, end = Infinity) {
26 return new SliceAsyncIterable(source, begin, end);
27}
28
29//# sourceMappingURL=slice.mjs.map