diff options
| author | bors <bors@rust-lang.org> | 2019-09-21 04:21:25 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-09-21 04:21:25 +0000 | 
| commit | 5349e69ae207c4d11245e75463c091eded3ad13c (patch) | |
| tree | edad552f0cdb10530194e80fc9010dac0dbda2b5 /src/libsyntax_ext/env.rs | |
| parent | 97e58c0d32bcb8730f8246d25f3d2fa8092b450a (diff) | |
| parent | 72175915d6ae5abbc45cf2860a90508d2b4a38ea (diff) | |
| download | rust-5349e69ae207c4d11245e75463c091eded3ad13c.tar.gz rust-5349e69ae207c4d11245e75463c091eded3ad13c.zip | |
Auto merge of #64047 - timvermeulen:cmp_min_max_by, r=cuviper
Add `cmp::{min_by, min_by_key, max_by, max_by_key}`
This adds the following functions to `core::cmp`:
- `min_by`
- `min_by_key`
- `max_by`
- `max_by_key`
`min_by` and `max_by` are somewhat trivial to implement, but not entirely because `min_by` returns the first value in case the two are equal (and `max_by` the second). `min` and `max` can be implemented in terms of `min_by` and `max_by`, but not as easily the other way around.
To give an example of why I think these functions could be useful: the `Iterator::{min_by, min_by_key, max_by, max_by_key}` methods all currently hard-code the behavior mentioned above which is an ever so small duplication of logic. If we delegate them to `cmp::{min_by, max_by}` methods instead, we get the correct behavior for free. (edit: this is now included in the PR)
I added `min_by_key` / `max_by_key` for consistency's sake but I wouldn't mind removing them. I don't have a particular use case in mind for them, and `min_by` / `max_by` seem to be more useful.
Tracking issue: #64460
Diffstat (limited to 'src/libsyntax_ext/env.rs')
0 files changed, 0 insertions, 0 deletions
