UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.65 kB
{"version":3,"sources":["iterable/operators/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,MAAM,OAAO,cAAwB,SAAQ,SAAkB;IAK7D,YACE,MAAyB,EACzB,SAAqD,EACrD,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,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YAC/B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;gBAClD,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAWD;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CACpB,SAAqD,EACrD,OAAa;IAEb,OAAO,SAAS,sBAAsB,CAAC,MAAyB;QAC9D,OAAO,IAAI,cAAc,CAAU,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC","file":"filter.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { OperatorFunction } from '../../interfaces';\n\nexport class FilterIterable<TSource> extends IterableX<TSource> {\n private _source: Iterable<TSource>;\n private _predicate: (value: TSource, index: number) => boolean;\n private _thisArg?: any;\n\n constructor(\n source: Iterable<TSource>,\n predicate: (value: TSource, index: number) => boolean,\n thisArg?: any\n ) {\n super();\n this._source = source;\n this._predicate = predicate;\n this._thisArg = thisArg;\n }\n\n *[Symbol.iterator]() {\n let i = 0;\n for (const item of this._source) {\n if (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): OperatorFunction<T, S>;\nexport function filter<T>(\n predicate: (value: T, index: number) => boolean,\n thisArg?: any\n): OperatorFunction<T, T>;\n\n/**\n * Filters the elements of an 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) => boolean)} predicate A function to test each source element for a condition.\n * @param {*} [thisArg] Optional this for binding.\n * @returns {OperatorFunction<TSource, TSource>} An operator which returns an 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) => boolean,\n thisArg?: any\n): OperatorFunction<TSource, TSource> {\n return function filterOperatorFunction(source: Iterable<TSource>): IterableX<TSource> {\n return new FilterIterable<TSource>(source, predicate, thisArg);\n };\n}\n"]}