ix
Version:
The Interactive Extensions for JavaScript
45 lines (43 loc) • 1.67 kB
JavaScript
import { __asyncGenerator, __await } from "tslib";
import { AsyncIterableX } from '../asynciterablex.mjs';
import { wrapWithAbort } from './withabort.mjs';
import { throwIfAborted } from '../../aborterror.mjs';
/** @ignore */
export class SkipAsyncIterable extends AsyncIterableX {
constructor(source, count) {
super();
this._source = source;
this._count = count;
}
[Symbol.asyncIterator](signal) {
return __asyncGenerator(this, arguments, function* _a() {
throwIfAborted(signal);
const source = wrapWithAbort(this._source, signal);
const it = source[Symbol.asyncIterator]();
let count = this._count;
let next;
while (count > 0 && !(next = yield __await(it.next())).done) {
count--;
}
if (count <= 0) {
while (!(next = yield __await(it.next())).done) {
yield yield __await(next.value);
}
}
});
}
}
/**
* Bypasses a specified number of elements in an async-iterable sequence and then returns the remaining elements.
*
* @template TSource The type of the elements in the source sequence.
* @param {number} count The number of elements to skip before returning the remaining elements.
* @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence that contains the elements that
* occur after the specified index in the input sequence.
*/
export function skip(count) {
return function skipOperatorFunction(source) {
return new SkipAsyncIterable(source, count);
};
}
//# sourceMappingURL=skip.mjs.map