UNPKG

ix

Version:

The Interactive Extensions for JavaScript

37 lines (35 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sequenceEqual = void 0; const tslib_1 = require("tslib"); const comparer_js_1 = require("../util/comparer.js"); const withabort_js_1 = require("./operators/withabort.js"); const aborterror_js_1 = require("../aborterror.js"); /** * Determines whether two sequences are equal by comparing the elements pairwise. * * @template T The type of the elements in the source sequence. * @param {AsyncIterable<T>} source First async-iterable sequence to compare. * @param {AsyncIterable<T>} other Second async-iterable sequence to compare. * @param {SequencEqualOptions<T>} [options] The sequence equal options which include an optional comparer and optional abort signal. * @returns {Promise<boolean>} A promise which indicates whether both sequences are of equal length and their * corresponding elements are equal. */ function sequenceEqual(source, other, options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const { ['comparer']: comparer = comparer_js_1.comparerAsync, ['signal']: signal } = options || {}; (0, aborterror_js_1.throwIfAborted)(signal); const it1 = (0, withabort_js_1.wrapWithAbort)(source, signal)[Symbol.asyncIterator](); const it2 = (0, withabort_js_1.wrapWithAbort)(other, signal)[Symbol.asyncIterator](); let next1; let next2; while (!(next1 = yield it1.next()).done) { if (!(!(next2 = yield it2.next()).done && (yield comparer(next1.value, next2.value)))) { return false; } } return !!(yield it2.next()).done; }); } exports.sequenceEqual = sequenceEqual; //# sourceMappingURL=sequenceequal.js.map