@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 3.88 kB
Source Map (JSON)
{"version":3,"sources":["asynciterable/operators/distinct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,OAAO,qBAA+C,SAAQ,cAAuB;IAKzF,YACE,MAA8B,EAC9B,WAA2E,EAC3E,QAA0D;QAE1D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,MAAM,GAAG,GAAG,EAAY,CAAC;QAEzB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,MAAM,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC9D,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,CACtC,MAA8B;QAE9B,MAAM,EAAE,CAAC,aAAa,CAAC,EAAE,WAAW,GAAG,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,aAAa,EAAE,GAC5F,OAAO,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,qBAAqB,CAAgB,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC","file":"distinct.js","sourcesContent":["import { AsyncIterableX } from './../asynciterablex';\nimport { identityAsync } from '../../util/identity';\nimport { arrayIndexOfAsync } from '../../util/arrayindexof';\nimport { comparerAsync } from '../../util/comparer';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\nimport { DistinctOptions } from './distinctoptions';\n\nexport class DistinctAsyncIterable<TSource, TKey = TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _keySelector: (value: TSource, signal?: AbortSignal) => TKey | Promise<TKey>;\n private _comparer: (x: TKey, y: TKey) => boolean | Promise<boolean>;\n\n constructor(\n source: AsyncIterable<TSource>,\n keySelector: (value: TSource, signal?: AbortSignal) => TKey | Promise<TKey>,\n comparer: (x: TKey, y: TKey) => boolean | Promise<boolean>\n ) {\n super();\n this._source = source;\n this._keySelector = keySelector;\n this._comparer = comparer;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n const set = [] as TKey[];\n\n for await (const item of wrapWithAbort(this._source, signal)) {\n const key = await this._keySelector(item, signal);\n if ((await arrayIndexOfAsync(set, key, this._comparer)) === -1) {\n set.push(key);\n yield item;\n }\n }\n }\n}\n\n/**\n * Returns an async-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 = TSource>} [options] The optional arguments for a key selector and comparer function.\n * @returns {MonoTypeOperatorAsyncFunction<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): MonoTypeOperatorAsyncFunction<TSource> {\n return function distinctOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource> {\n const { ['keySelector']: keySelector = identityAsync, ['comparer']: comparer = comparerAsync } =\n options || {};\n return new DistinctAsyncIterable<TSource, TKey>(source, keySelector, comparer);\n };\n}\n"]}