@@ -2546,6 +2546,16 @@ pub trait Iterator {
2546
2546
2547
2547
/// Lexicographically compares the elements of this `Iterator` with those
2548
2548
/// of another.
2549
+ ///
2550
+ /// # Examples
2551
+ ///
2552
+ /// ```
2553
+ /// use std::cmp::Ordering;
2554
+ ///
2555
+ /// assert_eq!([1].iter().cmp([1].iter()), Ordering::Equal);
2556
+ /// assert_eq!([1].iter().cmp([1, 2].iter()), Ordering::Less);
2557
+ /// assert_eq!([1, 2].iter().cmp([1].iter()), Ordering::Greater);
2558
+ /// ```
2549
2559
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2550
2560
fn cmp < I > ( mut self , other : I ) -> Ordering where
2551
2561
I : IntoIterator < Item = Self :: Item > ,
@@ -2578,6 +2588,18 @@ pub trait Iterator {
2578
2588
2579
2589
/// Lexicographically compares the elements of this `Iterator` with those
2580
2590
/// of another.
2591
+ ///
2592
+ /// # Examples
2593
+ ///
2594
+ /// ```
2595
+ /// use std::cmp::Ordering;
2596
+ ///
2597
+ /// assert_eq!([1.].iter().partial_cmp([1.].iter()), Some(Ordering::Equal));
2598
+ /// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
2599
+ /// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
2600
+ ///
2601
+ /// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None);
2602
+ /// ```
2581
2603
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2582
2604
fn partial_cmp < I > ( mut self , other : I ) -> Option < Ordering > where
2583
2605
I : IntoIterator ,
@@ -2610,6 +2632,13 @@ pub trait Iterator {
2610
2632
2611
2633
/// Determines if the elements of this `Iterator` are equal to those of
2612
2634
/// another.
2635
+ ///
2636
+ /// # Examples
2637
+ ///
2638
+ /// ```
2639
+ /// assert_eq!([1].iter().eq([1].iter()), true);
2640
+ /// assert_eq!([1].iter().eq([1, 2].iter()), false);
2641
+ /// ```
2613
2642
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2614
2643
fn eq < I > ( mut self , other : I ) -> bool where
2615
2644
I : IntoIterator ,
@@ -2635,6 +2664,13 @@ pub trait Iterator {
2635
2664
2636
2665
/// Determines if the elements of this `Iterator` are unequal to those of
2637
2666
/// another.
2667
+ ///
2668
+ /// # Examples
2669
+ ///
2670
+ /// ```
2671
+ /// assert_eq!([1].iter().ne([1].iter()), false);
2672
+ /// assert_eq!([1].iter().ne([1, 2].iter()), true);
2673
+ /// ```
2638
2674
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2639
2675
fn ne < I > ( self , other : I ) -> bool where
2640
2676
I : IntoIterator ,
@@ -2646,6 +2682,14 @@ pub trait Iterator {
2646
2682
2647
2683
/// Determines if the elements of this `Iterator` are lexicographically
2648
2684
/// less than those of another.
2685
+ ///
2686
+ /// # Examples
2687
+ ///
2688
+ /// ```
2689
+ /// assert_eq!([1].iter().lt([1].iter()), false);
2690
+ /// assert_eq!([1].iter().lt([1, 2].iter()), true);
2691
+ /// assert_eq!([1, 2].iter().lt([1].iter()), false);
2692
+ /// ```
2649
2693
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2650
2694
fn lt < I > ( self , other : I ) -> bool where
2651
2695
I : IntoIterator ,
@@ -2657,6 +2701,14 @@ pub trait Iterator {
2657
2701
2658
2702
/// Determines if the elements of this `Iterator` are lexicographically
2659
2703
/// less or equal to those of another.
2704
+ ///
2705
+ /// # Examples
2706
+ ///
2707
+ /// ```
2708
+ /// assert_eq!([1].iter().le([1].iter()), true);
2709
+ /// assert_eq!([1].iter().le([1, 2].iter()), true);
2710
+ /// assert_eq!([1, 2].iter().le([1].iter()), false);
2711
+ /// ```
2660
2712
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2661
2713
fn le < I > ( self , other : I ) -> bool where
2662
2714
I : IntoIterator ,
@@ -2671,6 +2723,14 @@ pub trait Iterator {
2671
2723
2672
2724
/// Determines if the elements of this `Iterator` are lexicographically
2673
2725
/// greater than those of another.
2726
+ ///
2727
+ /// # Examples
2728
+ ///
2729
+ /// ```
2730
+ /// assert_eq!([1].iter().gt([1].iter()), false);
2731
+ /// assert_eq!([1].iter().gt([1, 2].iter()), false);
2732
+ /// assert_eq!([1, 2].iter().gt([1].iter()), true);
2733
+ /// ```
2674
2734
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2675
2735
fn gt < I > ( self , other : I ) -> bool where
2676
2736
I : IntoIterator ,
@@ -2682,6 +2742,14 @@ pub trait Iterator {
2682
2742
2683
2743
/// Determines if the elements of this `Iterator` are lexicographically
2684
2744
/// greater than or equal to those of another.
2745
+ ///
2746
+ /// # Examples
2747
+ ///
2748
+ /// ```
2749
+ /// assert_eq!([1].iter().ge([1].iter()), true);
2750
+ /// assert_eq!([1].iter().ge([1, 2].iter()), false);
2751
+ /// assert_eq!([1, 2].iter().ge([1].iter()), true);
2752
+ /// ```
2685
2753
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
2686
2754
fn ge < I > ( self , other : I ) -> bool where
2687
2755
I : IntoIterator ,
@@ -2730,6 +2798,18 @@ pub trait Iterator {
2730
2798
/// function to determine the ordering of two elements. Apart from that, it's equivalent to
2731
2799
/// [`is_sorted`]; see its documentation for more information.
2732
2800
///
2801
+ /// # Examples
2802
+ ///
2803
+ /// ```
2804
+ /// #![feature(is_sorted)]
2805
+ ///
2806
+ /// assert!([1, 2, 2, 9].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
2807
+ /// assert!(![1, 3, 2, 4].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
2808
+ /// assert!([0].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
2809
+ /// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| a.partial_cmp(b)));
2810
+ /// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
2811
+ /// ```
2812
+ ///
2733
2813
/// [`is_sorted`]: trait.Iterator.html#method.is_sorted
2734
2814
#[ unstable( feature = "is_sorted" , reason = "new API" , issue = "53485" ) ]
2735
2815
fn is_sorted_by < F > ( mut self , mut compare : F ) -> bool
0 commit comments