pub trait IterFirstMaxExt: Iterator + Sized {
// Provided methods
fn first_max(self) -> Option<Self::Item>
where Self::Item: Ord { ... }
fn first_max_by<F>(self, f: F) -> Option<Self::Item>
where F: FnMut(&Self::Item, &Self::Item) -> Ordering { ... }
fn first_max_by_key<B, F>(self, f: F) -> Option<Self::Item>
where F: FnMut(&Self::Item) -> B,
B: Ord { ... }
}Expand description
Iterator::max* returns the last for equal keys,
this crate implements the return the first
use iter_first_max::IterFirstMaxExt as _;
let arr = [(0, 0), (1, 1), (2, 2), (2, 3), (2, 4)];
let last = arr.iter().max_by_key(|n| n.0);
let first = arr.iter().first_max_by_key(|n| n.0);
assert_eq!(last, Some(&(2, 4)));
assert_eq!(first, Some(&(2, 2)));Provided Methods§
Sourcefn first_max(self) -> Option<Self::Item>
fn first_max(self) -> Option<Self::Item>
Get max element, if equal, return the first equal element
Sourcefn first_max_by<F>(self, f: F) -> Option<Self::Item>
fn first_max_by<F>(self, f: F) -> Option<Self::Item>
Get max element, if equal, return the first equal element
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.