UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

75 lines (73 loc) 3.17 kB
import { __extends, __generator, __values } from "tslib"; import { IterableX } from '../iterablex.js'; import { identity } from '../../util/identity.js'; import { arrayIndexOf } from '../../util/arrayindexof.js'; import { comparer as defaultComparer } from '../../util/comparer.js'; /** @ignore */ var DistinctIterable = /** @class */ (function (_super) { __extends(DistinctIterable, _super); function DistinctIterable(source, keySelector, cmp) { var _this = _super.call(this) || this; _this._source = source; _this._keySelector = keySelector; _this._cmp = cmp; return _this; } DistinctIterable.prototype[Symbol.iterator] = function () { var set, _a, _b, item, key, e_1_1; var e_1, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: set = []; _d.label = 1; case 1: _d.trys.push([1, 6, 7, 8]); _a = __values(this._source), _b = _a.next(); _d.label = 2; case 2: if (!!_b.done) return [3 /*break*/, 5]; item = _b.value; key = this._keySelector(item); if (!(arrayIndexOf(set, key, this._cmp) === -1)) return [3 /*break*/, 4]; set.push(key); return [4 /*yield*/, item]; case 3: _d.sent(); _d.label = 4; case 4: _b = _a.next(); return [3 /*break*/, 2]; case 5: return [3 /*break*/, 8]; case 6: e_1_1 = _d.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 8]; case 7: try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } return [7 /*endfinally*/]; case 8: return [2 /*return*/]; } }); }; return DistinctIterable; }(IterableX)); export { DistinctIterable }; /** * Returns an iterable sequence that contains only distinct elements according to the keySelector and comparer. * * @template TSource The type of the elements in the source sequence. * @template TKey The type of the discriminator key computed for each element in the source sequence. * @param {DistinctOptions<TSource, TKey>} [options] The optional arguments for a key selector and comparer function. * @returns {MonoTypeOperatorFunction<TSource>} An operator that returns distinct elements according to the keySelector and options. */ export function distinct(options) { return function distinctOperatorFunction(source) { var _a = options || {}, _b = _a["keySelector"], keySelector = _b === void 0 ? identity : _b, _c = _a["comparer"], comparer = _c === void 0 ? defaultComparer : _c; return new DistinctIterable(source, keySelector, comparer); }; } //# sourceMappingURL=distinct.js.map