-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add _.comparator and align sortedIndex to sortBy #1939
Conversation
@@ -394,7 +388,7 @@ | |||
var low = 0, high = array.length; | |||
while (low < high) { | |||
var mid = low + high >>> 1; | |||
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid; | |||
if (_.comparitor(value, iteratee(array[mid])) === 1) low = mid + 1; else high = mid; |
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.
LMK if stylistically you prefer above or
if (_.comparitor(iteratee(array[mid]), value) < 0) low = mid + 1; else high = mid;
It's spelled "comparator". |
Is the idea that this is something we should be exposing as a public method? If so, what's the use case? If not, let's make it an internal function. |
Why is this exposed? I'd prefer we not expose it. edit: I didn't refresh the page, and crossed paths with @jashkenas. |
@jashkenas @michaelficarra I exposed it because of #1768 (comment) Also allows some sanity checking unit tests which will be inheritted by |
Can we get this in/reviewed? I'll rebase this in a minute |
LGTM. |
Add _.comparator and align sortedIndex to sortBy
How does this affect the performance of Also is Reducing duplication and exposing a |
I think whatever the hit on As for the name I'm not partial to |
I've worked pretty hard at maintaining the perf of The perf concern for |
Eh, this will need another look I suppose |
Anyway I'm a big fan of exposing comparator as it allows devs easy
|
That's great but Underscore isn't your personal toy store. These things need a bit more hammering before introducing into core. Answering my previous question:
Up to a 73% hit for |
Right. Let's please back this out for now. |
I don't think we need to back this out. We can improve the perf of the implementation for sure and argue over whether it should be exposed or not but I think its a change for the better |
Backing it out isn't the end of the road. |
Can you expand on this? Wouldn't you just return a different value or use |
To repeat -- let's please back this out for the time being. (I don't want to forget about it.) |
@braddunbar lets say you want to to do add support to something similar to pythons class _.mixin({
comparator: _.wrap(_.compatator, function(baseCompare, a, b) {
if (_.isFunction(b.__cmp__)) return b.__cmp__(a);
if (_.isFunction(a.__cmp__) return a.__cmp__(b);
return baseCompare(a, b);
})
}); |
Resolves #1768 and fixes #1834
This could use some review and thoughts