Created
June 2, 2016 23:48
-
-
Save tomenden/49908892bdbc271bf55f5541ade56273 to your computer and use it in GitHub Desktop.
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
function* gen() { | |
const three = yield 'three'; | |
const two = yield 'two'; | |
const sum = yield `${two}, ${three}`; | |
return sum; | |
} | |
const iterable = gen(); // the generator instance folllws the iterable protocol | |
iterable.next() | |
// {value: "three", done: false} | |
iterable.next() | |
// {value: "two", done: false} | |
iterable.next() | |
// {value: "undefined, undefined", done: false} | |
iterable.next() | |
// {value: undefined, done: true} | |
iterable.next() | |
// {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment