function* range (min: number, max: number): Generator<number> {
for(let i = min; i <= max; i++) {
yield i
}
}
type MapPredicate<T, K> = (input: T, output: K);
function* map<T, K>(iter: Generator<T>, functor: MapPredicate<T, K>): Generator<K> {
for(let el of iter) {
yield functor(el)
}
}
const generator = map(range(1, 5), i => i * 2)
console.log(generator)
for(let element of generator) {
console.log(element)
}