Skip to content

Instantly share code, notes, and snippets.

@tomenden
Created June 2, 2016 23:48
Show Gist options
  • Save tomenden/49908892bdbc271bf55f5541ade56273 to your computer and use it in GitHub Desktop.
Save tomenden/49908892bdbc271bf55f5541ade56273 to your computer and use it in GitHub Desktop.
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