UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 3.25 kB
{"version":3,"sources":["asynciterable/operators/filter.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,mBAA6B,SAAQ,cAAuB;IAKvE,YACE,MAA8B,EAC9B,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,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,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;AAWD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CACpB,SAA8F,EAC9F,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';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class FilterAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _predicate: (value: TSource, index: number) => boolean | Promise<boolean>;\n private _thisArg: any;\n\n constructor(\n source: 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](signal?: AbortSignal) {\n throwIfAborted(signal);\n let i = 0;\n for await (const item of wrapWithAbort(this._source, signal)) {\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>;\n\n/**\n * Filters the elements of an async-iterable sequence based on a predicate.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {((value: TSource, index: number, signal?: AbortSignal) => boolean | Promise<boolean>)} predicate A function to test each source element\n * for a condition.\n * @param {*} [thisArg] Optional this for binding.\n * @returns {OperatorAsyncFunction<TSource, TSource>} An operator which returns an async-iterable\n * sequence that contains elements from the input sequence that satisfy the condition.\n */\nexport function filter<TSource>(\n predicate: (value: TSource, index: number, signal?: AbortSignal) => 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"]}