@@ -4105,6 +4105,26 @@ pub trait Itertools: Iterator {
41054105 ///
41064106 /// The keys can be floats but no particular result is guaranteed
41074107 /// if a key is NaN.
4108+ ///
4109+ /// # Examples
4110+ /// ```
4111+ /// use itertools::Itertools;
4112+ /// use itertools::MinMaxResult::{MinMax, NoElements, OneElement};
4113+ ///
4114+ /// let abs_key = |x: &&i32| x.abs();
4115+ ///
4116+ /// let a: [i32; 0] = [];
4117+ /// assert_eq!(a.iter().minmax_by_key(abs_key), NoElements);
4118+ ///
4119+ /// let a = [1];
4120+ /// assert_eq!(a.iter().minmax_by_key(abs_key), OneElement(&1));
4121+ ///
4122+ /// let a = [-2, -1, 0, 1, 2];
4123+ /// assert_eq!(a.iter().minmax_by_key(abs_key), MinMax(&0, &2));
4124+ ///
4125+ /// let a = [1, 1, 1, 1];
4126+ /// assert_eq!(a.iter().minmax_by_key(abs_key), MinMax(&1, &1));
4127+ /// ```
41084128 fn minmax_by_key < K , F > ( self , key : F ) -> MinMaxResult < Self :: Item >
41094129 where
41104130 Self : Sized ,
@@ -4122,6 +4142,27 @@ pub trait Itertools: Iterator {
41224142 /// For the minimum, the first minimal element is returned. For the maximum,
41234143 /// the last maximal element wins. This matches the behavior of the standard
41244144 /// [`Iterator::min`] and [`Iterator::max`] methods.
4145+ ///
4146+ /// # Examples
4147+ ///
4148+ /// ```
4149+ /// use itertools::Itertools;
4150+ /// use itertools::MinMaxResult::{MinMax, NoElements, OneElement};
4151+ ///
4152+ /// let abs_cmp = |x: &&i32, y: &&i32| x.abs().cmp(&y.abs());
4153+ ///
4154+ /// let a: [i32; 0] = [];
4155+ /// assert_eq!(a.iter().minmax_by(&abs_cmp), NoElements);
4156+ ///
4157+ /// let a = [1];
4158+ /// assert_eq!(a.iter().minmax_by(&abs_cmp), OneElement(&1));
4159+ ///
4160+ /// let a = [-2, -1, 0, 1, 2];
4161+ /// assert_eq!(a.iter().minmax_by(&abs_cmp), MinMax(&0, &2));
4162+ ///
4163+ /// let a = [1, 1, 1, 1];
4164+ /// assert_eq!(a.iter().minmax_by(&abs_cmp), MinMax(&1, &1));
4165+ /// ```
41254166 fn minmax_by < F > ( self , mut compare : F ) -> MinMaxResult < Self :: Item >
41264167 where
41274168 Self : Sized ,
0 commit comments