Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
Created November 25, 2014 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmueller/9b8b59d552f90425ee41 to your computer and use it in GitHub Desktop.
Save matthewmueller/9b8b59d552f90425ee41 to your computer and use it in GitHub Desktop.
Generator Flow
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