UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

30 lines (28 loc) 1.05 kB
import { AsyncIterableX } from './../asynciterablex'; import { identityAsync } from '../../util/identity'; import { arrayIndexOfAsync } from '../../util/arrayindexof'; import { comparerAsync } from '../../util/comparer'; export class DistinctAsyncIterable extends AsyncIterableX { constructor(source, keySelector, comparer) { super(); this._source = source; this._keySelector = keySelector; this._comparer = comparer; } async *[Symbol.asyncIterator]() { const set = []; for await (const item of this._source) { const key = await this._keySelector(item); if ((await arrayIndexOfAsync(set, key, this._comparer)) === -1) { set.push(key); yield item; } } } } export function distinct(keySelector = identityAsync, comparer = comparerAsync) { return function distinctOperatorFunction(source) { return new DistinctAsyncIterable(source, keySelector, comparer); }; } //# sourceMappingURL=distinct.mjs.map