import { IterableX } from './iterablex' ; import { returnIterator } from '../util/returniterator' ; export class CatchIterable < TSource > extends IterableX < TSource > { private _source : Iterable < Iterable < TSource > > ; constructor ( source ) { super ( ) ; this . _source = source ; } * [ Symbol . iterator ] ( ) { let error = null ; let hasError = false ; for ( const source of this . _source ) { const it = source [ Symbol . iterator ] ( ) ; error = null ; hasError = false ; while ( 1 ) { let c = < TSource > { } ; try { const { done , value } = it . next ( ) ; if ( done ) { returnIterator ( it ) ; break ; } c = value ; } catch ( e ) { error = e ; hasError = true ; returnIterator ( it ) ; break ; } yield c ; } if ( ! hasError ) { break ; } } if ( hasError ) { throw error ; } } } param { Iterable < Iterable < TSource > > } source return { Iterable < TSource > } export function catchAll < TSource > ( source ) { return new CatchIterable < TSource > ( source ) ; } param { ... Iterable < TSource > } source return { Iterable < TSource > } export function catchError < TSource > ( ... source ) { return new CatchIterable < TSource > ( source ) ; }