@@ -4026,42 +4026,42 @@ pub trait Iterator {
40264026 Self : Sized ,
40274027 Self :: Item : PartialOrd ,
40284028 {
4029- self . is_sorted_by ( PartialOrd :: partial_cmp )
4029+ self . is_sorted_by ( |a , b| a <= b )
40304030 }
40314031
40324032 /// Checks if the elements of this iterator are sorted using the given comparator function.
40334033 ///
40344034 /// Instead of using `PartialOrd::partial_cmp`, this function uses the given `compare`
4035- /// function to determine the ordering of two elements. Apart from that, it's equivalent to
4036- /// [`is_sorted`]; see its documentation for more information.
4035+ /// function to determine whether two elements are to be considered in sorted order.
40374036 ///
40384037 /// # Examples
40394038 ///
40404039 /// ```
40414040 /// #![feature(is_sorted)]
40424041 ///
4043- /// assert!([1, 2, 2, 9].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
4044- /// assert!(![1, 3, 2, 4].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
4045- /// assert!([0].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
4046- /// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| a.partial_cmp(b)));
4047- /// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
4048- /// ```
4042+ /// assert!([1, 2, 2, 9].iter().is_sorted_by(|a, b| a <= b));
4043+ /// assert!(![1, 2, 2, 9].iter().is_sorted_by(|a, b| a < b));
40494044 ///
4050- /// [`is_sorted`]: Iterator::is_sorted
4045+ /// assert!([0].iter().is_sorted_by(|a, b| true));
4046+ /// assert!([0].iter().is_sorted_by(|a, b| false));
4047+ ///
4048+ /// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| false));
4049+ /// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| true));
4050+ /// ```
40514051 #[ unstable( feature = "is_sorted" , reason = "new API" , issue = "53485" ) ]
40524052 #[ rustc_do_not_const_check]
40534053 fn is_sorted_by < F > ( mut self , compare : F ) -> bool
40544054 where
40554055 Self : Sized ,
4056- F : FnMut ( & Self :: Item , & Self :: Item ) -> Option < Ordering > ,
4056+ F : FnMut ( & Self :: Item , & Self :: Item ) -> bool ,
40574057 {
40584058 #[ inline]
40594059 fn check < ' a , T > (
40604060 last : & ' a mut T ,
4061- mut compare : impl FnMut ( & T , & T ) -> Option < Ordering > + ' a ,
4061+ mut compare : impl FnMut ( & T , & T ) -> bool + ' a ,
40624062 ) -> impl FnMut ( T ) -> bool + ' a {
40634063 move |curr| {
4064- if let Some ( Ordering :: Greater ) | None = compare ( & last, & curr) {
4064+ if ! compare ( & last, & curr) {
40654065 return false ;
40664066 }
40674067 * last = curr;
0 commit comments