Forwarding `return()` in generators

Brendan Eich brendan at
Fri Mar 27 09:26:14 UTC 2015

Brendan Eich wrote:
> Axel Rauschmayer wrote:
>> It’d be great if all iterables were indeed the same in this regard.

I didn't reply to this last sentence. I don't agree that all iterables 
(we don't control the universe of such things, so perhaps you mean all 
standardized or built-in iterables) vend iterators with return methods. 
It's rare to both break from a for-of loop and want to iterate more 
after, so you're in hard-cases-make-bad-law land right there.

Iterators are best used by getting fresh ones and consuming them till 
"done" (whether exhausted or not). `return` is required only if an 
iterator hangs onto a scarce-enough resource. Many (most?) iterators do not.


More information about the es-discuss mailing list