@@ -54,29 +54,17 @@ where
54
54
}
55
55
56
56
#[ inline]
57
- fn fold < B , F > ( self , mut acc : B , mut f : F ) -> B
57
+ fn fold < B , F > ( self , mut init : B , mut f : F ) -> B
58
58
where
59
59
Self : Sized ,
60
60
F : FnMut ( B , Self :: Item ) -> B ,
61
61
{
62
- let ZipLongest { mut a, mut b } = self ;
63
-
64
- loop {
65
- match ( a. next ( ) , b. next ( ) ) {
66
- ( Some ( x) , Some ( y) ) => acc = f ( acc, EitherOrBoth :: Both ( x, y) ) ,
67
- ( Some ( x) , None ) => {
68
- acc = f ( acc, EitherOrBoth :: Left ( x) ) ;
69
- // b is exhausted, so we can drain a.
70
- return a. fold ( acc, |acc, x| f ( acc, EitherOrBoth :: Left ( x) ) ) ;
71
- }
72
- ( None , Some ( y) ) => {
73
- acc = f ( acc, EitherOrBoth :: Right ( y) ) ;
74
- // a is exhausted, so we can drain b.
75
- return b. fold ( acc, |acc, y| f ( acc, EitherOrBoth :: Right ( y) ) ) ;
76
- }
77
- ( None , None ) => return acc, // Both iterators are exhausted.
78
- }
79
- }
62
+ let ZipLongest { a, mut b } = self ;
63
+ init = a. fold ( init, |init, a| match b. next ( ) {
64
+ Some ( b) => f ( init, EitherOrBoth :: Both ( a, b) ) ,
65
+ None => f ( init, EitherOrBoth :: Left ( a) ) ,
66
+ } ) ;
67
+ b. fold ( init, |init, b| f ( init, EitherOrBoth :: Right ( b) ) )
80
68
}
81
69
}
82
70
0 commit comments