UNPKG

2.76 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/filterasync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,cAAwB,SAAQ,cAAuB;IAI3D,YACE,MAAyE,EACzE,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,IAA6B,IAAI,CAAC,OAAO,EAAE;YAC9D,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;gBACpC,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAmBD,MAAM,UAAU,WAAW,CACzB,MAAuD,EACvD,SAAkE,EAClE,OAAa;IAEb,OAAO,IAAI,cAAc,CAAI,MAAM,EAAE,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC","file":"filterasync.js","sourcesContent":["import { AsyncIterableX } from '../asynciterable';\nimport { bindCallback } from '../util/bindcallback';\n\nclass FilterIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: Iterable<TSource | PromiseLike<TSource>> | AsyncIterable<TSource>;\n private _predicate: (value: TSource, index: number) => boolean | Promise<boolean>;\n\n constructor(\n source: Iterable<TSource | PromiseLike<TSource>> | 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 <AsyncIterable<TSource>> this._source) {\n if (await this._predicate(item, i++)) {\n yield item;\n }\n }\n }\n}\n\n/**\n * Filters a sequence of values based on a predicate.\n * @param {Iterable<T | Promise<T>> | AsyncIterable<T>} source Source sequence.\n * @param {function(value: T, index: number): boolean | Promise<boolean>} predicate A function to test each source element for a condition.\n * @param {Object} [thisArg] Value to use as this when executing callback.\n * @return {AsyncIterable<T>} Sequence that contains elements from the input sequence that satisfy the condition.\n */\nexport function filterAsync<T, S extends T>(\n source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>,\n predicate: (value: T, index: number) => value is S,\n thisArg?: any\n): AsyncIterableX<S>;\nexport function filterAsync<T>(\n source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>,\n predicate: (value: T, index: number) => boolean | Promise<boolean>,\n thisArg?: any\n): AsyncIterableX<T>;\nexport function filterAsync<T>(\n source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>,\n predicate: (value: T, index: number) => boolean | Promise<boolean>,\n thisArg?: any\n): AsyncIterableX<T> {\n return new FilterIterable<T>(source, bindCallback(predicate, thisArg, 2));\n}\n"]}
\No newline at end of file