Skip to content

Instantly share code, notes, and snippets.

@bendc
Created January 26, 2016 09:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendc/8041f7144a7e3b667ea8 to your computer and use it in GitHub Desktop.
Save bendc/8041f7144a7e3b667ea8 to your computer and use it in GitHub Desktop.
Make objects iterable
const iterable = function* (obj) {
yield* Object.keys(obj).map(key => [key, obj[key]]);
};
@bendc
Copy link
Author

bendc commented Jan 26, 2016

Example:

const obj = iterable({
  a: 1,
  b: 2
});

obj.next(); // => value: ["a", 1], done: false
obj.next(); // => value: ["b", 2], done: false
obj.next(); // => value: undefined, done: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment