Created
December 9, 2015 12:46
-
-
Save bendc/ba511625d867873b9472 to your computer and use it in GitHub Desktop.
Iterate over an Iterator object using recursion
This file contains 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
const set = new Set(["foo", "bar"]); | |
const iterate = iterator => { | |
const iteration = iterator.next(); | |
if (iteration.done) return; | |
console.log(iteration.value); | |
return iterate(iterator); | |
}; | |
iterate(set.values()); // => foo, bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment