UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

34 lines (32 loc) 948 B
import { AsyncIterableX } from '../asynciterablex'; export class SliceAsyncIterable extends AsyncIterableX { constructor(source, begin, end) { super(); this._source = source; this._begin = begin; this._end = end; } async *[Symbol.asyncIterator]() { const it = this._source[Symbol.asyncIterator](); let begin = this._begin; let next; while (begin > 0 && !(next = await it.next()).done) { begin--; } let end = this._end; if (end > 0) { while (!(next = await it.next()).done) { yield next.value; if (--end === 0) { break; } } } } } export function slice(begin, end = Infinity) { return function sliceOperatorFunction(source) { return new SliceAsyncIterable(source, begin, end); }; } //# sourceMappingURL=slice.mjs.map