Skip to content

Instantly share code, notes, and snippets.

@GeraldHost
Created July 9, 2020 08:40
Show Gist options
  • Save GeraldHost/31bf09d15b3c2292a56bca245336d35c to your computer and use it in GitHub Desktop.
Save GeraldHost/31bf09d15b3c2292a56bca245336d35c to your computer and use it in GitHub Desktop.
Lazy Pipeline with Iterators
function* itOne(it) {
let current = it.next()
while(current.done == false){
console.log("ONE");
yield current.value + 2;
current = it.next();
}
}
function* itTwo(it) {
let current = it.next()
while(current.done == false){
console.log("TWO");
yield current.value + 2;
current = it.next();
}
}
function* gen() {
for(let i = 0; i < 5; i++){
yield i + 1;
}
}
const a = gen();
const b = itOne(a);
const c = itTwo(b);
for (const x of c) {
console.log(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment