import { AsyncIterableX } from '../asynciterablex' ; import { OperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class PairwiseAsyncIterable < TSource > extends AsyncIterableX < TSource [ ] > { private _source : AsyncIterable < TSource > ; constructor ( source ) { super ( ) ; this . _source = source ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; let value ; let hasValue = false ; for await ( const item of wrapWithAbort ( this . _source , signal ) ) { if ( ! hasValue ) { hasValue = true ; } else { yield [ value ! , item ] ; } value = item ; } } } template TSource returns { OperatorAsyncFunction < TSource , TSource [ ] > } export function pairwise < TSource > ( ) { return function pairwiseOperatorFunction ( source ) : AsyncIterableX < TSource [ ] > { return new PairwiseAsyncIterable < TSource > ( source ) ; } ; }