Trait try_partialord::TryMinMax[][src]

pub trait TryMinMax<T> {
    fn try_select_by<F>(
        self,
        compare: F,
        target: Ordering
    ) -> OrderResult<Option<T>>
    where
        F: FnMut(&T, &T) -> Option<Ordering>
; fn try_min(self) -> OrderResult<Option<T>>
    where
        T: PartialOrd<T>,
        Self: Sized
, { ... }
fn try_min_by<F>(self, compare: F) -> OrderResult<Option<T>>
    where
        F: FnMut(&T, &T) -> Option<Ordering>,
        Self: Sized
, { ... }
fn try_min_by_key<K, F>(self, f: F) -> OrderResult<Option<T>>
    where
        F: FnMut(&T) -> Option<K>,
        K: PartialOrd<K>,
        Self: Sized
, { ... }
fn try_max(self) -> OrderResult<Option<T>>
    where
        T: PartialOrd<T>,
        Self: Sized
, { ... }
fn try_max_by<F>(self, compare: F) -> OrderResult<Option<T>>
    where
        F: FnMut(&T, &T) -> Option<Ordering>,
        Self: Sized
, { ... }
fn try_max_by_key<K, F>(self, f: F) -> OrderResult<Option<T>>
    where
        F: FnMut(&T) -> Option<K>,
        K: PartialOrd<K>,
        Self: Sized
, { ... } }

Min and max methods for PartialOrd

use try_partialord::*;
use rand::distributions::Standard;
use rand::prelude::*;

let rng = thread_rng();
let mut v: Vec<f32> = Standard.sample_iter(rng).take(100).collect();
let min = v.iter().try_min().unwrap();
assert_eq!(min, v.iter().min_by(|a, b| a.partial_cmp(b).unwrap()));

// min is error because of uncompareabale value `NAN`
v.push(f32::NAN);
let min = v.iter().try_min();
assert!(min.is_err());

Required methods

fn try_select_by<F>(
    self,
    compare: F,
    target: Ordering
) -> OrderResult<Option<T>> where
    F: FnMut(&T, &T) -> Option<Ordering>, 
[src]

Base method for getting min or max. target is to tell what you want to get is min or max.

Loading content...

Provided methods

fn try_min(self) -> OrderResult<Option<T>> where
    T: PartialOrd<T>,
    Self: Sized
[src]

PartialOrd version for Iterator::min.

fn try_min_by<F>(self, compare: F) -> OrderResult<Option<T>> where
    F: FnMut(&T, &T) -> Option<Ordering>,
    Self: Sized
[src]

PartialOrd version for Iterator::min_by.

fn try_min_by_key<K, F>(self, f: F) -> OrderResult<Option<T>> where
    F: FnMut(&T) -> Option<K>,
    K: PartialOrd<K>,
    Self: Sized
[src]

PartialOrd version for Iterator::min_by_key.

fn try_max(self) -> OrderResult<Option<T>> where
    T: PartialOrd<T>,
    Self: Sized
[src]

PartialOrd version for Iterator::max.

fn try_max_by<F>(self, compare: F) -> OrderResult<Option<T>> where
    F: FnMut(&T, &T) -> Option<Ordering>,
    Self: Sized
[src]

PartialOrd version for Iterator::max_by.

fn try_max_by_key<K, F>(self, f: F) -> OrderResult<Option<T>> where
    F: FnMut(&T) -> Option<K>,
    K: PartialOrd<K>,
    Self: Sized
[src]

PartialOrd version for Iterator::max_by_key.

Loading content...

Implementors

impl<T, Iter> TryMinMax<T> for Iter where
    Iter: IntoIterator<Item = T>, 
[src]

Loading content...