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§

source

fn min_max(self) -> Option<(Self::Item, Self::Item)>
where Self: Sized, Self::Item: Ord + Clone,

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 does 1.5 * n comparisons, so it is faster than calling min and max separately which does 2 * n comparisons.
source

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,

Returns the minimum and maximum element with respect to the given comparison function.

See min_max for more details.

source

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,

Returns the minimum and maximum element with respect to element returned from the given key function.

See min_max for more details.

Implementors§

source§

impl<I> IterMinMax for I
where I: Iterator + ?Sized,