> The idea that iterators return themselves from their @@iterator (__iter__) > hook has years of actual programmer mileage in Python. I take that experience > seriously, compared to arguments from purity that tax the common use-cases.
I’d be happy with either solution, but let’s compare: AFAICT, the tax is on for-of (and Array.from()): they need to additionally check whether an object is an iterator. On the other hand, turning every iterator into an iterable puts the burden on people implementing iterators: they have to implement the iterable interface. And it becomes harder to distinguish the interfaces, should you need to [1]. IMO, the purity argument also counts: this technique implies that iterators are a subset of iterables, but that isn’t true: For iterables, each invocation of `iterator` creates a new object, for iterators, it doesn’t. As an aside, Python 3 uses a special name for the `next` method (it previously didn’t). Maybe ES6 should use a symbol here, too. That would eliminate the concerns about false positives, should for-of ever work with iterators. [1] http://stackoverflow.com/questions/709084/how-to-tell-the-difference-between-an-iterator-and-an-iterable -- Dr. Axel Rauschmayer [email protected] home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

