@@ -54,29 +54,17 @@ where
5454    } 
5555
5656    #[ 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 
5858    where 
5959        Self :  Sized , 
6060        F :  FnMut ( B ,  Self :: Item )  -> B , 
6161    { 
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) ) ) 
8068    } 
8169} 
8270
0 commit comments