Check out Dart's iterators

Brendan Eich brendan at mozilla.com
Sun Feb 10 22:18:18 PST 2013


Claude Pache wrote:
> 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.
>>
>> /be
>
> By reading [1] (and PEP-380), it seems to me that the "value" property is rather set to be the value of the return statement.

Yes; also the StopIteration constructor's parameter for explicit 
constructions.

>   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)

Is 'source' worth its weight by default? Python manages without.

/be

>
> [1] http://wiki.ecmascript.org/doku.php?id=harmony:generators
>
> —Claude
>
>> 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 mailing list