4 ms·
That's great; you've really made this clear. In python, one would just use itertools.tee() to get multiple bites at a particular iterator, rather than relying o
by jessaustin 12y ago
That's great; you've really made this clear. In python, one would just use itertools.tee() to get multiple bites at a particular iterator, rather than relying on sugary syntax to instantiate the iterator multiple times; perhaps ES6 should have something similar? I have to say, this "Symbol.iterator" magic string seems like an even less felicitous way to write this than python's dunderous __iter__() function. Maybe coffeescript or one of its forks can help ES explore a more reasonable way to write this.
- picks_at_nits 12y agoWell, __iter__ was baked into Python decades(?) ago, so there’s no danger anybody might have their own __iter__ methods that mean something else. But now that JS is adding iteration methods to the language, there are lots of libraries and frameworks that have their own incompatible ways of greenspunning these features. The [Symbol.iterator] expression resolves to a string that is guaranteed to be unique, so there is no possibility of breaking backwards-compatibility with someone who picked the exact same magic name. (There’s a major headache involved when code crosses execution contexts, I don’t pretend to understand how that works yet.)