UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 4.59 kB
{"version":3,"sources":["asynciterable/operators/skipwhile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,sBAAgC,SAAQ,cAAuB;IAQ1E,YACE,MAA8B,EAC9B,SAA8F;QAE9F,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC/D,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,EAAE;gBAC/D,QAAQ,GAAG,IAAI,CAAC;aACjB;YACD,IAAI,QAAQ,EAAE;gBACZ,MAAM,OAAO,CAAC;aACf;SACF;IACH,CAAC;CACF;AA6BD;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CACvB,SAAkE;IAElE,OAAO,SAAS,yBAAyB,CAAC,MAAwB;QAChE,OAAO,IAAI,sBAAsB,CAAI,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC","file":"skipwhile.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { OperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class SkipWhileAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _predicate: (\n value: TSource,\n index: number,\n signal?: AbortSignal\n ) => boolean | Promise<boolean>;\n\n constructor(\n source: AsyncIterable<TSource>,\n predicate: (value: TSource, index: number, signal?: AbortSignal) => boolean | Promise<boolean>\n ) {\n super();\n this._source = source;\n this._predicate = predicate;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n let yielding = false;\n let i = 0;\n for await (const element of wrapWithAbort(this._source, signal)) {\n if (!yielding && !(await this._predicate(element, i++, signal))) {\n yielding = true;\n }\n if (yielding) {\n yield element;\n }\n }\n }\n}\n\n/**\n * Bypasses elements in an async-iterale sequence as long as a specified condition is true\n * and then returns the remaining elements.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @template S The result of the predicate that is truthy/falsy.\n * @param {(value: T, index: number, signal?: AbortSignal) => value is S} predicate A function to test each element for a condition.\n * @returns {OperatorAsyncFunction<T, S>} An async-iterable sequence that contains the elements from the input\n * sequence starting at the first element in the linear series that does not pass the test specified by predicate.\n */\nexport function skipWhile<T, S extends T>(\n predicate: (value: T, index: number, signal?: AbortSignal) => value is S\n): OperatorAsyncFunction<T, S>;\n/**\n * Bypasses elements in an async-iterale sequence as long as a specified condition is true\n * and then returns the remaining elements.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @param {((value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>)} predicate A function to test each element for a condition.\n * @returns {OperatorAsyncFunction<T, T>} An async-iterable sequence that contains the elements from the input\n * sequence starting at the first element in the linear series that does not pass the test specified by predicate.\n */\nexport function skipWhile<T>(\n predicate: (value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>\n): OperatorAsyncFunction<T, T>;\n/**\n * Bypasses elements in an async-iterale sequence as long as a specified condition is true\n * and then returns the remaining elements.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @param {((value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>)} predicate A function to test each element for a condition.\n * @returns {OperatorAsyncFunction<T, T>} An async-iterable sequence that contains the elements from the input\n * sequence starting at the first element in the linear series that does not pass the test specified by predicate.\n */\nexport function skipWhile<T>(\n predicate: (value: T, index: number) => boolean | Promise<boolean>\n): OperatorAsyncFunction<T, T> {\n return function skipWhileOperatorFunction(source: AsyncIterable<T>): AsyncIterableX<T> {\n return new SkipWhileAsyncIterable<T>(source, predicate);\n };\n}\n"]}