Skip to content

Commit 7c9ac4f

Browse files
Rollup merge of #38995 - petrochenkov:minmax, r=GuillaumeGomez
Fix docs for min/max algorithms I thought at first "what did they think about when stabilizing this!?", but it turned out it's just wrong docs. Phew. r? @steveklabnik Test: ``` use std::cmp::Ordering; struct S(u8, u8); impl PartialEq for S { fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } impl PartialOrd for S { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.0.cmp(&other.0)) } } impl Ord for S { fn cmp(&self, other: &Self) -> Ordering { self.0.cmp(&other.0) } } fn main() { let arr = [S(0, 1), S(0, 2)]; println!("min {:?}", arr.iter().min()); println!("min_by {:?}", arr.iter().min_by(|x, y| x.0.cmp(&y.0))); println!("min_by_key {:?}", arr.iter().min_by_key(|x| x.0)); println!("max {:?}", arr.iter().max()); println!("max_by {:?}", arr.iter().max_by(|x, y| x.0.cmp(&y.0))); println!("max_by_key {:?}", arr.iter().max_by_key(|x| x.0)); } ``` Output: ``` rustc 1.15.0-beta.3 (a035041 2017-01-07) min Some(S(0, 1)) min_by Some(S(0, 1)) min_by_key Some(S(0, 1)) max Some(S(0, 2)) max_by Some(S(0, 2)) max_by_key Some(S(0, 2)) ```
2 parents 6d2fb12 + bf02534 commit 7c9ac4f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/libcore/iter/iterator.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ pub trait Iterator {
16121612

16131613
/// Returns the maximum element of an iterator.
16141614
///
1615-
/// If the two elements are equally maximum, the latest element is
1615+
/// If several elements are equally maximum, the last element is
16161616
/// returned.
16171617
///
16181618
/// # Examples
@@ -1638,7 +1638,7 @@ pub trait Iterator {
16381638

16391639
/// Returns the minimum element of an iterator.
16401640
///
1641-
/// If the two elements are equally minimum, the first element is
1641+
/// If several elements are equally minimum, the first element is
16421642
/// returned.
16431643
///
16441644
/// # Examples
@@ -1665,8 +1665,8 @@ pub trait Iterator {
16651665
/// Returns the element that gives the maximum value from the
16661666
/// specified function.
16671667
///
1668-
/// Returns the rightmost element if the comparison determines two elements
1669-
/// to be equally maximum.
1668+
/// If several elements are equally maximum, the last element is
1669+
/// returned.
16701670
///
16711671
/// # Examples
16721672
///
@@ -1690,8 +1690,8 @@ pub trait Iterator {
16901690
/// Returns the element that gives the maximum value with respect to the
16911691
/// specified comparison function.
16921692
///
1693-
/// Returns the rightmost element if the comparison determines two elements
1694-
/// to be equally maximum.
1693+
/// If several elements are equally maximum, the last element is
1694+
/// returned.
16951695
///
16961696
/// # Examples
16971697
///
@@ -1715,8 +1715,8 @@ pub trait Iterator {
17151715
/// Returns the element that gives the minimum value from the
17161716
/// specified function.
17171717
///
1718-
/// Returns the latest element if the comparison determines two elements
1719-
/// to be equally minimum.
1718+
/// If several elements are equally minimum, the first element is
1719+
/// returned.
17201720
///
17211721
/// # Examples
17221722
///
@@ -1739,8 +1739,8 @@ pub trait Iterator {
17391739
/// Returns the element that gives the minimum value with respect to the
17401740
/// specified comparison function.
17411741
///
1742-
/// Returns the latest element if the comparison determines two elements
1743-
/// to be equally minimum.
1742+
/// If several elements are equally minimum, the first element is
1743+
/// returned.
17441744
///
17451745
/// # Examples
17461746
///

0 commit comments

Comments
 (0)