@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 3.23 kB
Source Map (JSON)
{"version":3,"sources":["iterable/operators/distinct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAIlE,MAAM,OAAO,gBAA0C,SAAQ,SAAkB;IAK/E,YACE,MAAyB,EACzB,WAAqC,EACrC,GAAkC;QAElC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,GAAG,GAAG,EAAY,CAAC;QAEzB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC5C,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAwC;IAExC,OAAO,SAAS,wBAAwB,CAAC,MAAyB;QAChE,MAAM,EAAE,CAAC,aAAa,CAAC,EAAE,WAAW,GAAG,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,eAAe,EAAE,GACzF,OAAO,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,gBAAgB,CAAgB,MAAM,EAAE,WAAY,EAAE,QAAS,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC","file":"distinct.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { identity } from '../../util/identity';\nimport { arrayIndexOf } from '../../util/arrayindexof';\nimport { comparer as defaultComparer } from '../../util/comparer';\nimport { MonoTypeOperatorFunction } from '../../interfaces';\nimport { DistinctOptions } from './distinctoptions';\n\nexport class DistinctIterable<TSource, TKey = TSource> extends IterableX<TSource> {\n private _source: Iterable<TSource>;\n private _keySelector: (value: TSource) => TKey;\n private _cmp: (x: TKey, y: TKey) => boolean;\n\n constructor(\n source: Iterable<TSource>,\n keySelector: (value: TSource) => TKey,\n cmp: (x: TKey, y: TKey) => boolean\n ) {\n super();\n this._source = source;\n this._keySelector = keySelector;\n this._cmp = cmp;\n }\n\n *[Symbol.iterator]() {\n const set = [] as TKey[];\n\n for (const item of this._source) {\n const key = this._keySelector(item);\n if (arrayIndexOf(set, key, this._cmp) === -1) {\n set.push(key);\n yield item;\n }\n }\n }\n}\n\n/**\n * Returns an iterable sequence that contains only distinct elements according to the keySelector and comparer.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @template TKey The type of the discriminator key computed for each element in the source sequence.\n * @param {DistinctOptions<TSource, TKey>} [options] The optional arguments for a key selector and comparer function.\n * @returns {MonoTypeOperatorFunction<TSource>} An operator that returns distinct elements according to the keySelector and options.\n */\nexport function distinct<TSource, TKey = TSource>(\n options?: DistinctOptions<TSource, TKey>\n): MonoTypeOperatorFunction<TSource> {\n return function distinctOperatorFunction(source: Iterable<TSource>): IterableX<TSource> {\n const { ['keySelector']: keySelector = identity, ['comparer']: comparer = defaultComparer } =\n options || {};\n return new DistinctIterable<TSource, TKey>(source, keySelector!, comparer!);\n };\n}\n"]}