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

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Jun 12 09:13:27 PDT 2013


On Jun 12, 2013, at 8:17 AM, Jason Orendorff wrote:

> On Tue, Jun 11, 2013 at 12:53 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> But, really, for-of (and Arrray.from and friends) should just accept either an Iterable or an Iterator with priority given to Iterable
> 
> Then the above an most conveniently be coded as:
> 
> function giveMeAEmptyIterator( ) {
>    return  {
>        next() {return {done: true}},
>    }
> }
> 
> More convenient still:
> 
>     function *giveMeAEmptyIterator() {}
> 
> This will work fine even if for-of remains as currently specified (unconditionally calling the @@iterator method, as I think it should).
> 
> -j


Yes, but the point was to illustrate what it looks like for folks who choose not to use a generator function.  In general, I agree that using generators is usually what you want to do. 

Allen

> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130612/4fdc94ba/attachment.html>


More information about the es-discuss mailing list