UNPKG

ix

Version:

The Interactive Extensions for JavaScript

57 lines (55 loc) 2.33 kB
import { __asyncGenerator, __asyncValues, __await } from "tslib"; import { AsyncIterableX } from '../asynciterablex.mjs'; import { wrapWithAbort } from './withabort.mjs'; import { throwIfAborted } from '../../aborterror.mjs'; /** @ignore */ export class SkipWhileAsyncIterable extends AsyncIterableX { constructor(source, predicate) { super(); this._source = source; this._predicate = predicate; } [Symbol.asyncIterator](signal) { return __asyncGenerator(this, arguments, function* _a() { var _b, e_1, _c, _d; throwIfAborted(signal); let yielding = false; let i = 0; try { for (var _e = true, _f = __asyncValues(wrapWithAbort(this._source, signal)), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) { _d = _g.value; _e = false; const element = _d; if (!yielding && !(yield __await(this._predicate(element, i++, signal)))) { yielding = true; } if (yielding) { yield yield __await(element); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f)); } finally { if (e_1) throw e_1.error; } } }); } } /** * Bypasses elements in an async-iterale sequence as long as a specified condition is true * and then returns the remaining elements. * * @template T The type of the elements in the source sequence. * @param {((value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>)} predicate A function to test each element for a condition. * @returns {OperatorAsyncFunction<T, T>} An async-iterable sequence that contains the elements from the input * sequence starting at the first element in the linear series that does not pass the test specified by predicate. */ export function skipWhile(predicate) { return function skipWhileOperatorFunction(source) { return new SkipWhileAsyncIterable(source, predicate); }; } //# sourceMappingURL=skipwhile.mjs.map