-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add CollectionUtils.some() to allow breaking out of iteration #3117
Conversation
To @peterflynn |
An alternative to this could be a new |
I've been using |
@@ -62,7 +62,29 @@ define(function (require, exports, module) { | |||
} | |||
} | |||
|
|||
/** | |||
* Iterates over all the properties in an object or elements in an array. If a callback returns a | |||
* truthly value then it will inmediatelly return true, if not, it will return false. Differs from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "inmediatelly" -> "immediately"
@TomMalbran done reviewing. Two comment nits plus this bigger question about whether we want to rename the API. We should probably wait a day or so to see if others chime in on that. |
It seems like I missed several cases when switching $.each with forEach where the loop broke. This fixes one of those cases, since it needs |
@peterflynn It's been a few days, and nothing happened, should we just leave like it is. The names make sense since the functions work for any collection, and JavaScript already implements different APIs with the same names. |
Add CollectionUtils.some() to allow breaking out of iteration
Clarifying title (was: "Break the CollectionUtils.forEach loop if the callback returns false") |
@peterflynn Great, I am glad that this is finally merged :) I know it shouldn't be used for arrays, but it is possible. It would work great when the object could be either an array or an object. Thanks for changing the name, this pull went from breaking the loop to creating a new method. |
Yeah -- thanks for generalizing it that way btw. We will definitely have more places to use this :-) |
Since we will be using this function a lot more, this change would make it really useful to do a search inside an object and stop when finding the result by making the callback return a value that will be false once the search is done. This is the same way that jQuery uses to break the .each loops.