Thoughts about the generators module
Closed this issue · 3 comments
This isn't really an "issue", but more a few thoughts that occurred to me while I was looking at the generators
module.
For the simple cases given, the exported functions in generators
don't actually need to be generator functions. I understand that it's certainly more interesting to show different features working together, but in each case the array returned by Object.keys(obj)
actually provides the necessary iterators, take a look:
export function* values(obj) {
for (let key of Object.keys(obj)) {
yield obj[key];
}
}
// is the same as:
export function values(obj) {
return Object.keys(obj).values();
}
...And so forth.
Of course it's perfectly fine and correct to leave as is :)
Strike all of that, silly me... I completely read past the return value there. Sorry for the noise!!
Interestingly, the generators
module is very similar to the proposed dict
module for ES7, which returns entries
, keys
and values
functions that are generic :)
I'm very happy that is being added in ES7. No point in having everybody write that themselves.