@@ -1900,7 +1900,8 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
1900
1900
1901
1901
#[ inline]
1902
1902
fn next ( & mut self ) -> Option < B > {
1903
- self . iter . next ( ) . and_then ( |a| ( self . f ) ( & mut self . state , a) )
1903
+ let a = self . iter . next ( ) ?;
1904
+ ( self . f ) ( & mut self . state , a)
1904
1905
}
1905
1906
1906
1907
#[ inline]
@@ -1910,17 +1911,25 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
1910
1911
}
1911
1912
1912
1913
#[ inline]
1913
- fn try_fold < Acc , Fold , R > ( & mut self , init : Acc , mut fold : Fold ) -> R where
1914
+ fn try_fold < Acc , Fold , R > ( & mut self , init : Acc , fold : Fold ) -> R where
1914
1915
Self : Sized , Fold : FnMut ( Acc , Self :: Item ) -> R , R : Try < Ok =Acc >
1915
1916
{
1917
+ fn scan < ' a , T , St , B , Acc , R : Try < Ok = Acc > > (
1918
+ state : & ' a mut St ,
1919
+ f : & ' a mut impl FnMut ( & mut St , T ) -> Option < B > ,
1920
+ mut fold : impl FnMut ( Acc , B ) -> R + ' a ,
1921
+ ) -> impl FnMut ( Acc , T ) -> LoopState < Acc , R > + ' a {
1922
+ move |acc, x| {
1923
+ match f ( state, x) {
1924
+ None => LoopState :: Break ( Try :: from_ok ( acc) ) ,
1925
+ Some ( x) => LoopState :: from_try ( fold ( acc, x) ) ,
1926
+ }
1927
+ }
1928
+ }
1929
+
1916
1930
let state = & mut self . state ;
1917
1931
let f = & mut self . f ;
1918
- self . iter . try_fold ( init, move |acc, x| {
1919
- match f ( state, x) {
1920
- None => LoopState :: Break ( Try :: from_ok ( acc) ) ,
1921
- Some ( x) => LoopState :: from_try ( fold ( acc, x) ) ,
1922
- }
1923
- } ) . into_try ( )
1932
+ self . iter . try_fold ( init, scan ( state, f, fold) ) . into_try ( )
1924
1933
}
1925
1934
}
1926
1935
0 commit comments