@@ -622,6 +622,24 @@ where
622
622
BothBackward | Back => self . b . get ( ) ,
623
623
}
624
624
}
625
+
626
+ #[ inline]
627
+ fn fold < Acc , F > ( self , init : Acc , mut f : F ) -> Acc
628
+ where
629
+ Self : Sized ,
630
+ F : FnMut ( Acc , & Self :: Item ) -> Acc ,
631
+ {
632
+ let mut accum = init;
633
+ match self . state {
634
+ ChainState :: Back => { }
635
+ _ => accum = self . a . fold ( accum, & mut f) ,
636
+ }
637
+ match self . state {
638
+ ChainState :: Front => { }
639
+ _ => accum = self . b . fold ( accum, & mut f) ,
640
+ }
641
+ accum
642
+ }
625
643
}
626
644
627
645
impl < A , B > DoubleEndedStreamingIterator for Chain < A , B >
@@ -646,6 +664,24 @@ where
646
664
Back => self . b . advance_back ( ) ,
647
665
}
648
666
}
667
+
668
+ #[ inline]
669
+ fn rfold < Acc , F > ( self , init : Acc , mut f : F ) -> Acc
670
+ where
671
+ Self : Sized ,
672
+ F : FnMut ( Acc , & Self :: Item ) -> Acc ,
673
+ {
674
+ let mut accum = init;
675
+ match self . state {
676
+ ChainState :: Front => { }
677
+ _ => accum = self . b . rfold ( accum, & mut f) ,
678
+ }
679
+ match self . state {
680
+ ChainState :: Back => { }
681
+ _ => accum = self . a . rfold ( accum, & mut f) ,
682
+ }
683
+ accum
684
+ }
649
685
}
650
686
651
687
/// A normal, non-streaming, iterator which converts the elements of a streaming iterator into owned
@@ -1031,6 +1067,20 @@ where
1031
1067
fn get ( & self ) -> Option < & Self :: Item > {
1032
1068
self . sub_iter . as_ref ( ) . and_then ( J :: get)
1033
1069
}
1070
+
1071
+ #[ inline]
1072
+ fn fold < Acc , Fold > ( self , init : Acc , mut fold : Fold ) -> Acc
1073
+ where
1074
+ Self : Sized ,
1075
+ Fold : FnMut ( Acc , & Self :: Item ) -> Acc ,
1076
+ {
1077
+ let mut acc = init;
1078
+ if let Some ( iter) = self . sub_iter {
1079
+ acc = iter. fold ( acc, & mut fold) ;
1080
+ }
1081
+ let mut f = self . f ;
1082
+ self . it . fold ( acc, |acc, item| f ( item) . fold ( acc, & mut fold) )
1083
+ }
1034
1084
}
1035
1085
1036
1086
/// A regular, non-streaming iterator which both filters and maps elements of a streaming iterator with a closure.
@@ -1200,6 +1250,19 @@ where
1200
1250
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1201
1251
self . it . size_hint ( )
1202
1252
}
1253
+
1254
+ #[ inline]
1255
+ fn fold < Acc , Fold > ( self , init : Acc , mut fold : Fold ) -> Acc
1256
+ where
1257
+ Self : Sized ,
1258
+ Fold : FnMut ( Acc , & Self :: Item ) -> Acc ,
1259
+ {
1260
+ let mut f = self . f ;
1261
+ self . it . fold ( init, |acc, item| {
1262
+ f ( item) ;
1263
+ fold ( acc, item)
1264
+ } )
1265
+ }
1203
1266
}
1204
1267
1205
1268
impl < I , F > DoubleEndedStreamingIterator for Inspect < I , F >
@@ -1212,6 +1275,19 @@ where
1212
1275
( self . f ) ( item) ;
1213
1276
}
1214
1277
}
1278
+
1279
+ #[ inline]
1280
+ fn rfold < Acc , Fold > ( self , init : Acc , mut fold : Fold ) -> Acc
1281
+ where
1282
+ Self : Sized ,
1283
+ Fold : FnMut ( Acc , & Self :: Item ) -> Acc ,
1284
+ {
1285
+ let mut f = self . f ;
1286
+ self . it . rfold ( init, |acc, item| {
1287
+ f ( item) ;
1288
+ fold ( acc, item)
1289
+ } )
1290
+ }
1215
1291
}
1216
1292
1217
1293
/// A streaming iterator which transforms the elements of a streaming iterator.
0 commit comments