Skip to content

Instantly share code, notes, and snippets.

@bendc bendc/iterable.js
Created Jan 26, 2016

Embed
What would you like to do?
Make objects iterable
const iterable = function* (obj) {
yield* Object.keys(obj).map(key => [key, obj[key]]);
};
@bendc

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.