UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.07 kB
{"version":3,"sources":["asynciterable/operators/takewhile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,MAAM,OAAO,sBAAgC,SAAQ,cAAuB;IAI1E,YACE,MAA8B,EAC9B,SAAwE;QAExE,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;QAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;gBACvC,MAAM;aACP;YACD,MAAM,IAAI,CAAC;SACZ;IACH,CAAC;CACF;AAQD,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":"takewhile.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { OperatorAsyncFunction } from '../../interfaces';\n\nexport class TakeWhileAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _predicate: (value: TSource, index: number) => boolean | Promise<boolean>;\n\n constructor(\n source: AsyncIterable<TSource>,\n predicate: (value: TSource, index: number) => boolean | Promise<boolean>\n ) {\n super();\n this._source = source;\n this._predicate = predicate;\n }\n\n async *[Symbol.asyncIterator]() {\n let i = 0;\n for await (const item of this._source) {\n if (!(await this._predicate(item, i++))) {\n break;\n }\n yield item;\n }\n }\n}\n\nexport function takeWhile<T, S extends T>(\n predicate: (value: T, index: number) => value is S\n): OperatorAsyncFunction<T, S>;\nexport function takeWhile<T>(\n predicate: (value: T, index: number) => boolean | Promise<boolean>\n): OperatorAsyncFunction<T, T>;\nexport function takeWhile<T>(\n predicate: (value: T, index: number) => boolean | Promise<boolean>\n): OperatorAsyncFunction<T, T> {\n return function takeWhileOperatorFunction(source: AsyncIterable<T>): AsyncIterableX<T> {\n return new TakeWhileAsyncIterable<T>(source, predicate);\n };\n}\n"]}