Skip to content

Commit

Permalink
Faster and implementation of some (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Jul 10, 2023
1 parent 6e0720c commit ad5aeb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions perf/List.js
Expand Up @@ -100,4 +100,14 @@ describe('List', function () {
list = list.asImmutable();
});
});

describe('some', function () {
it('100 000 items ', () => {
const list = Immutable.List();
for (let i = 0; i < 100000; i++) {
list.push(i);
}
list.some(item => item === 50000);
});
});
});
10 changes: 9 additions & 1 deletion src/CollectionImpl.js
Expand Up @@ -266,7 +266,15 @@ mixin(Collection, {
},

some(predicate, context) {
return !this.every(not(predicate), context);
assertNotInfinite(this.size);
let returnValue = false;
this.__iterate((v, k, c) => {
if (predicate.call(context, v, k, c)) {
returnValue = true;
return false;
}
});
return returnValue;
},

sort(comparator) {
Expand Down

0 comments on commit ad5aeb4

Please sign in to comment.