ix
Version:
The Interactive Extensions for JavaScript
33 lines (31 loc) • 1.52 kB
JavaScript
import { __awaiter } from "tslib";
import { comparerAsync } from '../util/comparer.mjs';
import { wrapWithAbort } from './operators/withabort.mjs';
import { throwIfAborted } from '../aborterror.mjs';
/**
* 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.
*/
export function sequenceEqual(source, other, options) {
return __awaiter(this, void 0, void 0, function* () {
const { ['comparer']: comparer = comparerAsync, ['signal']: signal } = options || {};
throwIfAborted(signal);
const it1 = wrapWithAbort(source, signal)[Symbol.asyncIterator]();
const it2 = 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;
});
}
//# sourceMappingURL=sequenceequal.mjs.map