1 | import { comparerAsync } from '../util/comparer';
|
2 | import { wrapWithAbort } from './operators/withabort';
|
3 | import { throwIfAborted } from '../aborterror';
|
4 | /**
|
5 | * Determines whether two sequences are equal by comparing the elements pairwise.
|
6 | *
|
7 | * @export
|
8 | * @template T The type of the elements in the source sequence.
|
9 | * @param {AsyncIterable<T>} source First async-iterable sequence to compare.
|
10 | * @param {AsyncIterable<T>} other Second async-iterable sequence to compare.
|
11 | * @param {SequencEqualOptions<T>} [options] The sequence equal options which include an optional comparer and optional abort signal.
|
12 | * @returns {Promise<boolean>} A promise which indicates whether both sequences are of equal length and their
|
13 | * corresponding elements are equal.
|
14 | */
|
15 | export async function sequenceEqual(source, other, options) {
|
16 | const { ['comparer']: comparer = comparerAsync, ['signal']: signal } = options || {};
|
17 | throwIfAborted(signal);
|
18 | const it1 = wrapWithAbort(source, signal)[Symbol.asyncIterator]();
|
19 | const it2 = wrapWithAbort(other, signal)[Symbol.asyncIterator]();
|
20 | let next1;
|
21 | let next2;
|
22 | while (!(next1 = await it1.next()).done) {
|
23 | if (!(!(next2 = await it2.next()).done && (await comparer(next1.value, next2.value)))) {
|
24 | return false;
|
25 | }
|
26 | }
|
27 | return !!(await it2.next()).done;
|
28 | }
|
29 |
|
30 | //# sourceMappingURL=sequenceequal.mjs.map
|