export class ChainedIterator < T > implements IterableIterator < T > { private _list : Iterator < T > [ ] ; constructor ( ... list ) { this . _list = list . reverse ( ) ; } [ Symbol . iterator ] ( ) { return this ; } next ( ) { if ( this . _list . length < 1 ) return { done : true , value : null } ; const last = this . _list [ this . _list . length - 1 ] ; const next = last . next ( ) ; if ( next . done ) { this . _list . pop ( ) ; return this . next ( ) ; } return next ; } }