last value from iterator
Domenic Denicola
d at domenic.me
Sun Apr 5 23:24:37 UTC 2015
I don't think it's good to think of the value sent with `done: true` as "one of the values." It's in a different category, and not part of the yielded sequence.
________________________________
From: Mark Volkmann<mailto:r.mark.volkmann at gmail.com>
Sent: 2015-04-05 18:43
To: Allen Wirfs-Brock<mailto:allen at wirfs-brock.com>
Cc: es-discuss list<mailto:es-discuss at mozilla.org>
Subject: Re: last value from iterator
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<mailto: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/f63d975a/attachment.html>
More information about the es-discuss
mailing list