import { IterableX } from '../iterablex' ; import { MonoTypeOperatorFunction } from '../../interfaces' ; export class DefaultIfEmptyIterable < TSource > extends IterableX < TSource > { private _source : Iterable < TSource > ; private _defaultValue : TSource ; constructor ( source , defaultValue ) { super ( ) ; this . _source = source ; this . _defaultValue = defaultValue ; } * [ Symbol . iterator ] ( ) { let state = 1 ; for ( const item of this . _source ) { state = 2 ; yield item ; } if ( state === 1 ) { yield this . _defaultValue ; } } } template T param { T } defaultValue returns { MonoTypeOperatorFunction < T > } export function defaultIfEmpty < T > ( defaultValue ) { return function defaultIfEmptyOperatorFunction ( source ) : IterableX < T > { return new DefaultIfEmptyIterable < T > ( source , defaultValue ) ; } ; }