Re: Why can’t for-of be applied to iterators?

Axel Rauschmayer axel at rauschma.de
Sun Jun 9 00:17:03 PDT 2013


> It seems easy enough to define a class that has a @@iterator() {return this} method and then to subclass class it for you specific Iterables.


One more thing that might be problematic with the current approach: If you create combinators for iterators (similar to Python’s itertools [1]) then the returned iterators also need to implement this pattern. Otherwise, for-of couldn’t iterate over them. Example:

    for(let elem of filter(keys(myObj), x => x.length > 0)) {
    }

Thus, the pattern becomes the norm instead of the exception. Then again, maybe that’s not a big deal, either.


[1] http://docs.python.org/3/library/itertools.html

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130609/d50d1c19/attachment-0001.html>


More information about the es-discuss mailing list