export class IteratorWrap { public returnValue: TReturn | null = null; constructor( private it: Generator ) { } *iter() { let next = this.it.next() while (!next.done) { yield next.value next = this.it.next() } this.returnValue = next.value } toArray() { return Array.from(this.iter()) } } export function* chain(genArray: Generator[]): Generator { for (const gen of genArray) { yield * gen } } export function* arrayToIter(arr: T[]): Generator { for (const e of arr) { yield e } }