UNPKG

ix

Version:

The Interactive Extensions for JavaScript

78 lines (76 loc) 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.except = exports.ExceptAsyncIterable = 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 ExceptAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(first, second, comparer) { super(); this._first = first; this._second = second; 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._second, signal)), _k; _k = yield tslib_1.__await(_j.next()), _b = _k.done, !_b; _h = true) { _d = _k.value; _h = false; const secondItem = _d; map.push(secondItem); } } 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._first, signal)), _o; _o = yield tslib_1.__await(_m.next()), _e = _o.done, !_e; _l = true) { _g = _o.value; _l = false; const firstItem = _g; if ((yield tslib_1.__await((0, arrayindexof_js_1.arrayIndexOfAsync)(map, firstItem, this._comparer))) === -1) { map.push(firstItem); yield yield tslib_1.__await(firstItem); } } } 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.ExceptAsyncIterable = ExceptAsyncIterable; /** * Produces the set difference of two async-iterable sequences by using the specified equality comparer to compare values. * * @template TSource The type of the elements of the input sequences. * @param {AsyncIterable<TSource>} second An async-iterable sequence whose elements that also occur in the * operator sequence will cause those elements to be removed from the returned sequence. * @param {((x: TSource, y: TSource) => boolean | Promise<boolean>)} [comparer=comparerAsync] An equality comparer to compare values * @returns {MonoTypeOperatorAsyncFunction<TSource>} An operator that returns a sequence that contains the set * difference of the elements of two sequences. */ function except(second, comparer = comparer_js_1.comparerAsync) { return function exceptOperatorFunction(first) { return new ExceptAsyncIterable(first, second, comparer); }; } exports.except = except; //# sourceMappingURL=except.js.map