Mark Volkmann (2015-04-05T22:43:20.000Z)
Thanks, that helps. I had been thinking that for-of was a model for how
iterators should be consumed.

When implementing any kind of iterator (generator or not), it seems
important to recognize that if you choose to return a value with done set
to true, you are precluding the use of for-of with that iterator (assuming
you want all the values).

On Sun, Apr 5, 2015 at 11:40 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>
wrote:

>
> On Apr 5, 2015, at 6:04 AM, Mark Volkmann wrote:
>
> I thought that when an iterator returns done: true, the value should not
> be used.
>
>
> Why do you think that?  The definition of the IteratorResult interface in
> the the ES6 spec. doesn't say that.
>
> However, if a generator function ends by returning a value, done will be
> true when that value is returned and the value should be used.
>
>
> *Could* be used.  Whether a generator or any Iterator provides a
> meaningful value when it reach the the 'done' state depends upon its
> specific definition.
>
> Given this, how can a consumer know the correct way to handle the value
> when done is true? Clearly consumers shouldn't have to be aware of whether
> the iterator is actually a generator and whether it ends by returning a
> value.
>
>
> An Iterator does not have to be a generator to provide a 'done' state
> value.  In general, If you are going to do anything other than basic
> iteration, such as is performed by for-of, you need to know about the
> specific Iterator you are using.
>
> Allen
>
>
>


-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150405/5c1f4870/attachment.html>
d at domenic.me (2015-04-14T22:23:45.237Z)
Thanks, that helps. I had been thinking that for-of was a model for how
iterators should be consumed.

When implementing any kind of iterator (generator or not), it seems
important to recognize that if you choose to return a value with done set
to true, you are precluding the use of for-of with that iterator (assuming
you want all the values).