Created
November 25, 2014 01:32
-
-
Save matthewmueller/9b8b59d552f90425ee41 to your computer and use it in GitHub Desktop.
Generator Flow
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 *something(msg) { | |
msg += yield msg; // yields "a", returns "b" | |
msg += yield msg; // yields "ab", returns "c" | |
msg += yield msg; // yields "abc", returns "d" | |
return msg; // returns "abcd" | |
} | |
var gen = something('a'); | |
console.log(gen.next().value); // a | |
console.log(gen.next('b').value); // ab | |
console.log(gen.next('c').value); // abc | |
console.log(gen.next('d').value); // abcd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment