Check out Dart's iterators
claude.pache at gmail.com
Sun Feb 10 21:55:49 PST 2013
Le 11 févr. 2013 à 06:25, Brendan Eich <brendan at mozilla.com> a écrit :
> This is exactly what's proposed for ES6, except s/.source/.value/. See also PEP-380.
By reading  (and PEP-380), it seems to me that the "value" property is rather set to be the value of the return statement. Thus, to be more complete and to avoid confusion: Inside a generator function, a return statement will throw a StopIteration instance with its "value" property set to the value of the return statement and its "source" property set to the generator iterator which is being terminated. You can create manually such a StopIteration with: new StopIteration(source, value)
> Claude Pache wrote:
>> In order to mitigate the problem, instead of throwing a generic StopIteration, I think we ought to throw a specific StopIteration instance with information on which iterator has thrown. More precisely, inside a generator function, a return statement will throw a StopIteration instance with its "source" property set to the generator iterator which was terminated.
>> For manually throwing a StopIteration from inside a "next" method of an iterator, we could use:
>> throw new StopIteration(this)
>> And instead of "e instanceof StopIteration", we may use a more precise check:
>> e instanceof StopIteration&& e.source === it
More information about the es-discuss