Trait itermore::IterMinMax
source · pub trait IterMinMax: Iterator {
// Provided methods
fn min_max(self) -> Option<(Self::Item, Self::Item)>
where Self: Sized,
Self::Item: Ord + Clone { ... }
fn min_max_by<F>(self, compare: F) -> Option<(Self::Item, Self::Item)>
where Self: Sized,
Self::Item: Clone,
F: FnMut(&Self::Item, &Self::Item) -> Ordering { ... }
fn min_max_by_key<F, K>(self, key: F) -> Option<(Self::Item, Self::Item)>
where Self: Sized,
Self::Item: Clone,
K: Ord + Clone,
F: FnMut(&Self::Item) -> K { ... }
}
Available on crate feature
min_max
only.Expand description
An extension trait that provides the min_max
method and friends for
iterators.
Provided Methods§
sourcefn min_max(self) -> Option<(Self::Item, Self::Item)>
fn min_max(self) -> Option<(Self::Item, Self::Item)>
Returns the minimum and maximum element in the iterator.
- If there are no elements then
None
is returned. - In the case of a single element the element is cloned and returned in both places.
- If several elements are equally minimum or maximum, the first element is returned.
- On an iterator of length
n
,min_max
does1.5 * n
comparisons, so it is faster than callingmin
andmax
separately which does2 * n
comparisons.