UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.42 kB
{"version":3,"sources":["asynciterable/operators/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,MAAM,OAAO,mBAA6B,SAAQ,cAAuB;IAKvE,YACE,MAAyE,EACzE,SAAwE,EACxE,OAAa;QAEb,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,KAAK,EAAE,MAAM,IAAI,IAA6B,IAAI,CAAC,OAAO,EAAE;YAC9D,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;gBACxD,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAUD,MAAM,UAAU,MAAM,CACpB,SAAwE,EACxE,OAAa;IAEb,OAAO,SAAS,sBAAsB,CAAC,MAA8B;QACnE,OAAO,IAAI,mBAAmB,CAAU,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC","file":"filter.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { OperatorAsyncFunction } from '../../interfaces';\n\nexport class FilterAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: Iterable<TSource | PromiseLike<TSource>> | AsyncIterable<TSource>;\n private _predicate: (value: TSource, index: number) => boolean | Promise<boolean>;\n private _thisArg: any;\n\n constructor(\n source: Iterable<TSource | PromiseLike<TSource>> | AsyncIterable<TSource>,\n predicate: (value: TSource, index: number) => boolean | Promise<boolean>,\n thisArg?: any\n ) {\n super();\n this._source = source;\n this._predicate = predicate;\n this._thisArg = thisArg;\n }\n\n async *[Symbol.asyncIterator]() {\n let i = 0;\n for await (const item of <AsyncIterable<TSource>> this._source) {\n if (await this._predicate.call(this._thisArg, item, i++)) {\n yield item;\n }\n }\n }\n}\n\nexport function filter<T, S extends T>(\n predicate: (value: T, index: number) => value is S,\n thisArg?: any\n): OperatorAsyncFunction<T, S>;\nexport function filter<T>(\n predicate: (value: T, index: number) => boolean | Promise<boolean>,\n thisArg?: any\n): OperatorAsyncFunction<T, T>;\nexport function filter<TSource>(\n predicate: (value: TSource, index: number) => boolean | Promise<boolean>,\n thisArg?: any\n): OperatorAsyncFunction<TSource, TSource> {\n return function filterOperatorFunction(source: AsyncIterable<TSource>): AsyncIterableX<TSource> {\n return new FilterAsyncIterable<TSource>(source, predicate, thisArg);\n };\n}\n"]}