Throwing StopIteration in array extras to stop the iteration

Oliver Hunt oliver at apple.com
Sun Mar 3 12:33:58 PST 2013


On Mar 3, 2013, at 12:05 PM, Brendan Eich <brendan at mozilla.com> wrote:

> (a) not a compatible change for engines already prototyping StopIteration.
> (b) wrong hammer for this nail.
> 
> Are the some and every names confusing? Would any and all be better?

I think the naming boat has sailed, and i'm not sure if any and all are superior anyway (the fact that this has come up is evidence of the similarity of the terms and futility of choosing one set of names to represent all things).  If someone really cares about it they'll just make aliases like all/any/$woo/etc..

> 
> I think this is an RTFM thing, and people are smart, they memorize what they need to know.
Agreed.

> 
> /be

--Oliver


> David Bruant wrote:
>> Le 03/03/2013 20:29, Brendan Eich a écrit :
>>> If you want some or every and not forEach, they are there -- use them. No exception required.
>> I've found myself multiple times in a situation where I needed the index of the first element responding to some conditions. I solved it the following way:
>> 
>>    var index;
>>    array.some(function(e, i){
>>        if(someCondition(e)){
>>            index = i;
>>            return false;
>>        }
>> 
>>        return true;
>>    })
>> 
>> It works, but felt a bit awkward. It's a hack on .some because there is no other way to stop an iteration in other array methods.
>> Also spending hours on debugging because someone confused "some" for "every" (mixed the meaning of true/false) isn't fun.
>> 
>>    var index;
>>    array.forEach(function(e, i){
>>        if(someCondition(e)){
>>            index = i;
>>            throw StopIteration;
>>        }
>>    })
>> 
>> would look more explicit in my opinion.
>> 
>> David
>> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list