Created
July 9, 2020 08:40
-
-
Save GeraldHost/31bf09d15b3c2292a56bca245336d35c to your computer and use it in GitHub Desktop.
Lazy Pipeline with Iterators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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