@@ -1783,7 +1783,8 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
1783
1783
1784
1784
#[ inline]
1785
1785
fn next ( & mut self ) -> Option < B > {
1786
- self . iter . next ( ) . and_then ( |a| ( self . f ) ( & mut self . state , a) )
1786
+ let a = self . iter . next ( ) ?;
1787
+ ( self . f ) ( & mut self . state , a)
1787
1788
}
1788
1789
1789
1790
#[ inline]
@@ -1793,17 +1794,25 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
1793
1794
}
1794
1795
1795
1796
#[ inline]
1796
- fn try_fold < Acc , Fold , R > ( & mut self , init : Acc , mut fold : Fold ) -> R where
1797
+ fn try_fold < Acc , Fold , R > ( & mut self , init : Acc , fold : Fold ) -> R where
1797
1798
Self : Sized , Fold : FnMut ( Acc , Self :: Item ) -> R , R : Try < Ok =Acc >
1798
1799
{
1800
+ fn scan < ' a , T , St , B , Acc , R : Try < Ok = Acc > > (
1801
+ state : & ' a mut St ,
1802
+ f : & ' a mut impl FnMut ( & mut St , T ) -> Option < B > ,
1803
+ mut fold : impl FnMut ( Acc , B ) -> R + ' a ,
1804
+ ) -> impl FnMut ( Acc , T ) -> LoopState < Acc , R > + ' a {
1805
+ move |acc, x| {
1806
+ match f ( state, x) {
1807
+ None => LoopState :: Break ( Try :: from_ok ( acc) ) ,
1808
+ Some ( x) => LoopState :: from_try ( fold ( acc, x) ) ,
1809
+ }
1810
+ }
1811
+ }
1812
+
1799
1813
let state = & mut self . state ;
1800
1814
let f = & mut self . f ;
1801
- self . iter . try_fold ( init, move |acc, x| {
1802
- match f ( state, x) {
1803
- None => LoopState :: Break ( Try :: from_ok ( acc) ) ,
1804
- Some ( x) => LoopState :: from_try ( fold ( acc, x) ) ,
1805
- }
1806
- } ) . into_try ( )
1815
+ self . iter . try_fold ( init, scan ( state, f, fold) ) . into_try ( )
1807
1816
}
1808
1817
}
1809
1818
0 commit comments