-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tracking issue for slice::sort_by_key #30423
Comments
🔔 This issue is now entering its final comment period for stabilization 🔔 |
There is a function related to
|
An excellent point! I'll see if I can't add that soon to sneak it in for this FCP as well |
Hm actually, now that I think about it I'm not quite sure what the signature for fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
where F: FnOnce(&Self::Item) -> B, B: Ord; Is that what you were thinking as well? |
Yes. I suggest renaming |
Hm this may actually be a case where I'm not sure the extra method may buy much, for example compare: slice.binary_search_by(|k| k.key.cmp(&val));
// vs
slice.binary_search_by_key(&val, |k| &k.key); The |
For search with closures that maybe the case, but for search with methods or functions s.sort_by_key(Point::x);
// this is more readable
s.binary_search_by_key(&1, Point::x);
// than this
s.binary_search_by(|p| p.x().cmp(&1)); |
Oh hm yeah, good point! |
The libs team discussed this recently and the decision was to stabilize |
Closed by #30943 |
Should we open another issue for |
This method adds to the family of `_by_key` methods, and is the counterpart of `slice::sort_by_key`. It was mentioned on rust-lang#30423 but was not implemented at that time. Refs rust-lang#30423
As-is on the tin, mirrors the recently-stabilized
min_by_key
andmax_by_key
methods onIterator
.The text was updated successfully, but these errors were encountered: