Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Last active September 17, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickaelandrieu/25672eca6fa449c63e25ab3b84419532 to your computer and use it in GitHub Desktop.
Save mickaelandrieu/25672eca6fa449c63e25ab3b84419532 to your computer and use it in GitHub Desktop.
ES6 array iterator using generator
/**
* let it = arrayIterator(['foo', 'bar', 'baz']);
* it.next().value; // "foo"
* it.next().value; // "bar"
* it.next().value; // "baz"
* it.next().value; // undefined
*/
function* arrayIterator() {
let array = arguments;
let index = 0;
yield* array[index];
index++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment