1
Vote

Any should stop searching when first item matches condition

description

Hi!

I think that, in order to increase performance, you should stop the Any search when an element matches the condition. For example:

var list=[{id:1},{id:2},{id:3}];
Enumarable.From(list).Any(function(x){
return x.id==1;
});

This Any should not search in all items if the first item matches. Result will not vary if more than one element matches.

Currently Any is searching in all the items of the enumerable.

Anyway, awesome library, congratulations!

comments

neuecc wrote Dec 14, 2012 at 4:51 PM

Thank you.

But
Currently Any is searching in all the items of the enumerable.
Is this right?

Currently Any implementation(ver 2.2.0.2) is

if (arguments.length == 0) return enumerator.MoveNext(); // case:function()

while (enumerator.MoveNext()) // case:function(predicate)
{
if (predicate(enumerator.Current())) return true;
}

return false;

search is stopped.