UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

80 lines (78 loc) 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.union = exports.UnionAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const arrayindexof_js_1 = require("../../util/arrayindexof.js"); const comparer_js_1 = require("../../util/comparer.js"); const withabort_js_1 = require("./withabort.js"); const aborterror_js_1 = require("../../aborterror.js"); /** @ignore */ class UnionAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(left, right, comparer) { super(); this._left = left; this._right = right; this._comparer = comparer; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { var _b, e_1, _c, _d, _e, e_2, _f, _g; (0, aborterror_js_1.throwIfAborted)(signal); const map = []; try { for (var _h = true, _j = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._left, signal)), _k; _k = yield tslib_1.__await(_j.next()), _b = _k.done, !_b; _h = true) { _d = _k.value; _h = false; const lItem = _d; if ((yield tslib_1.__await((0, arrayindexof_js_1.arrayIndexOfAsync)(map, lItem, this._comparer))) === -1) { map.push(lItem); yield yield tslib_1.__await(lItem); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_h && !_b && (_c = _j.return)) yield tslib_1.__await(_c.call(_j)); } finally { if (e_1) throw e_1.error; } } try { for (var _l = true, _m = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(this._right, signal)), _o; _o = yield tslib_1.__await(_m.next()), _e = _o.done, !_e; _l = true) { _g = _o.value; _l = false; const rItem = _g; if ((yield tslib_1.__await((0, arrayindexof_js_1.arrayIndexOfAsync)(map, rItem, this._comparer))) === -1) { map.push(rItem); yield yield tslib_1.__await(rItem); } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (!_l && !_e && (_f = _m.return)) yield tslib_1.__await(_f.call(_m)); } finally { if (e_2) throw e_2.error; } } }); } } exports.UnionAsyncIterable = UnionAsyncIterable; /** * Produces the set union of two sequences by using the given equality comparer. * * @template TSource The type of the elements of the input sequences. * @param {AsyncIterable<TSource>} right An async-iterable sequence whose distinct elements form the second set for the union. * @param {((x: TSource, y: TSource) => boolean | Promise<boolean>)} [comparer=comparerAsync] The equality comparer to compare values. * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence that contains the elements from both input sequences, * excluding duplicates. */ function union(right, comparer = comparer_js_1.comparerAsync) { return function unionOperatorFunction(left) { return new UnionAsyncIterable(left, right, comparer); }; } exports.union = union; //# sourceMappingURL=union.js.map