@@ -4026,42 +4026,42 @@ pub trait Iterator {
4026
4026
Self : Sized ,
4027
4027
Self :: Item : PartialOrd ,
4028
4028
{
4029
- self . is_sorted_by ( PartialOrd :: partial_cmp )
4029
+ self . is_sorted_by ( |a , b| a <= b )
4030
4030
}
4031
4031
4032
4032
/// Checks if the elements of this iterator are sorted using the given comparator function.
4033
4033
///
4034
4034
/// 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.
4037
4036
///
4038
4037
/// # Examples
4039
4038
///
4040
4039
/// ```
4041
4040
/// #![feature(is_sorted)]
4042
4041
///
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));
4049
4044
///
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
+ /// ```
4051
4051
#[ unstable( feature = "is_sorted" , reason = "new API" , issue = "53485" ) ]
4052
4052
#[ rustc_do_not_const_check]
4053
4053
fn is_sorted_by < F > ( mut self , compare : F ) -> bool
4054
4054
where
4055
4055
Self : Sized ,
4056
- F : FnMut ( & Self :: Item , & Self :: Item ) -> Option < Ordering > ,
4056
+ F : FnMut ( & Self :: Item , & Self :: Item ) -> bool ,
4057
4057
{
4058
4058
#[ inline]
4059
4059
fn check < ' a , T > (
4060
4060
last : & ' a mut T ,
4061
- mut compare : impl FnMut ( & T , & T ) -> Option < Ordering > + ' a ,
4061
+ mut compare : impl FnMut ( & T , & T ) -> bool + ' a ,
4062
4062
) -> impl FnMut ( T ) -> bool + ' a {
4063
4063
move |curr| {
4064
- if let Some ( Ordering :: Greater ) | None = compare ( & last, & curr) {
4064
+ if ! compare ( & last, & curr) {
4065
4065
return false ;
4066
4066
}
4067
4067
* last = curr;
0 commit comments