import { comparerAsync } from '../util/comparer' ; import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; interface template T export interface SequencEqualOptions < T > { memberof comparer ? : ( first : T , second : T ) => boolean | Promise < boolean > ; type { AbortSignal } memberof signal ? : AbortSignal ; } template T param { AsyncIterable < T > } source param { AsyncIterable < T > } other param { SequencEqualOptions < T > } options returns { Promise < boolean > } export async function sequenceEqual < T > ( source , other , options ? ) { 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 = await it1 . next ( ) ) . done ) { if ( ! ( ! ( next2 = await it2 . next ( ) ) . done && ( await comparer ( next1 . value , next2 . value ) ) ) ) { return false ; } } return ! ! ( await it2 . next ( ) ) . done ; }