@@ -605,37 +605,6 @@ impl<I, J, F> Iterator for MergeBy<I, J, F>
605
605
}
606
606
}
607
607
608
- impl < I , F , T > CoalesceBy < I , F , T >
609
- where I : Iterator
610
- {
611
- fn next_with ( & mut self ) -> Option < T >
612
- where F : CoalescePredicate < I :: Item , T >
613
- {
614
- // this fuses the iterator
615
- let mut last = match self . last . take ( ) {
616
- None => return None ,
617
- Some ( x) => x,
618
- } ;
619
- for next in & mut self . iter {
620
- match self . f . coalesce_pair ( last, next) {
621
- Ok ( joined) => last = joined,
622
- Err ( ( last_, next_) ) => {
623
- self . last = Some ( next_) ;
624
- return Some ( last_) ;
625
- }
626
- }
627
- }
628
-
629
- Some ( last)
630
- }
631
-
632
- fn size_hint_internal ( & self ) -> ( usize , Option < usize > ) {
633
- let ( low, hi) = size_hint:: add_scalar ( self . iter . size_hint ( ) ,
634
- self . last . is_some ( ) as usize ) ;
635
- ( ( low > 0 ) as usize , hi)
636
- }
637
- }
638
-
639
608
/// An iterator adaptor that may join together adjacent elements.
640
609
///
641
610
/// See [`.coalesce()`](../trait.Itertools.html#method.coalesce) for more information.
@@ -693,11 +662,27 @@ impl<I, F, T> Iterator for CoalesceBy<I, F, T>
693
662
type Item = T ;
694
663
695
664
fn next ( & mut self ) -> Option < Self :: Item > {
696
- self . next_with ( )
665
+ // this fuses the iterator
666
+ let mut last = match self . last . take ( ) {
667
+ None => return None ,
668
+ Some ( x) => x,
669
+ } ;
670
+ for next in & mut self . iter {
671
+ match self . f . coalesce_pair ( last, next) {
672
+ Ok ( joined) => last = joined,
673
+ Err ( ( last_, next_) ) => {
674
+ self . last = Some ( next_) ;
675
+ return Some ( last_) ;
676
+ }
677
+ }
678
+ }
679
+ Some ( last)
697
680
}
698
681
699
682
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
700
- self . size_hint_internal ( )
683
+ let ( low, hi) = size_hint:: add_scalar ( self . iter . size_hint ( ) ,
684
+ self . last . is_some ( ) as usize ) ;
685
+ ( ( low > 0 ) as usize , hi)
701
686
}
702
687
703
688
fn fold < Acc , FnAcc > ( self , acc : Acc , mut fn_acc : FnAcc ) -> Acc
0 commit comments