import { AsyncIterableX } from '../asynciterablex' ; import { OperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class SkipWhileAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _source : AsyncIterable < TSource > ; private _predicate : ( value : TSource , index : number , signal ? : AbortSignal ) => boolean | Promise < boolean > ; constructor ( source , predicate ) { super ( ) ; this . _source = source ; this . _predicate = predicate ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; let yielding = false ; let i = 0 ; for await ( const element of wrapWithAbort ( this . _source , signal ) ) { if ( ! yielding && ! ( await this . _predicate ( element , i ++ , signal ) ) ) { yielding = true ; } if ( yielding ) { yield element ; } } } } template T template S param { ( value : T , index : number , signal ? : AbortSignal ) => value is S } predicate returns { OperatorAsyncFunction < T , S > } export function skipWhile < T , S extends T > ( predicate ) ; template T param { ( ( value : T , index : number , signal ? : AbortSignal ) => boolean | Promise < boolean > ) } predicate returns { OperatorAsyncFunction < T , T > } export function skipWhile < T > ( predicate ) ; template T param { ( ( value : T , index : number , signal ? : AbortSignal ) => boolean | Promise < boolean > ) } predicate returns { OperatorAsyncFunction < T , T > } export function skipWhile < T > ( predicate ) { return function skipWhileOperatorFunction ( source ) : AsyncIterableX < T > { return new SkipWhileAsyncIterable < T > ( source , predicate ) ; } ; }