Throwing StopIteration in array extras to stop the iteration

Brendan Eich brendan at mozilla.com
Sun Mar 3 11:29:05 PST 2013


David Bruant wrote:
> Le 03/03/2013 19:56, Bjoern Hoehrmann a écrit :
>> * David Bruant wrote:
>>> One (minor) annoyance with forEach/map, etc. is that the enumeration
>>> "can't" be stopped until all elements have been traversed which doesn't
>>> suit every use case. One hack to stop the enumeration is to throw an
>>> error but that requires to wrap the .forEach call in a try/catch block
>>> which is annoying too for code readability.
>>>
>>> The iterator protocol defines the StopIteration value. What about
>>> reusing this value in the context of array extras?
>> Using exceptions for normal flow control seems like a bad idea to me.
> I could not agree more. But JavaScript is what it is. Iterators are 
> going to use throw StopIteration [1] too.
> It's been discussed recently [2]. There could be slightly more radical 
> ideas like the "endframe" thing I'm describing in the post, but I have 
> no hope that such an idea would be considered seriously, that's why I 
> haven't proposed it and only shared it as food for thought.

You are barking up the wrong tree, again (same tree!).

This whole thread is a red herring. If you want some or every and not 
forEach, they are there -- use them. No exception required.

/be


More information about the es-discuss mailing list