Skip to content

Commit 01b09b0

Browse files
LorenzSchuelercuviper
authored andcommitted
add fold and fold_mut
1 parent 03220e0 commit 01b09b0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,16 @@ where
13191319
fn get(&self) -> Option<&Self::Item> {
13201320
self.iter.get().and_then(|iter| iter.get())
13211321
}
1322+
1323+
#[inline]
1324+
fn fold<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1325+
where
1326+
Self: Sized,
1327+
Fold: FnMut(Acc, &Self::Item) -> Acc,
1328+
{
1329+
self.iter
1330+
.fold_mut(init, |acc, item| item.fold(acc, &mut fold))
1331+
}
13221332
}
13231333

13241334
impl<I, J> StreamingIteratorMut for Flatten<I>
@@ -1330,6 +1340,16 @@ where
13301340
fn get_mut(&mut self) -> Option<&mut Self::Item> {
13311341
self.iter.get_mut().and_then(J::get_mut)
13321342
}
1343+
1344+
#[inline]
1345+
fn fold_mut<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1346+
where
1347+
Self: Sized,
1348+
Fold: FnMut(Acc, &mut Self::Item) -> Acc,
1349+
{
1350+
self.iter
1351+
.fold_mut(init, |acc, item| item.fold_mut(acc, &mut fold))
1352+
}
13331353
}
13341354

13351355
/// A regular, non-streaming iterator which both filters and maps elements of a streaming iterator with a closure.

0 commit comments

Comments
 (0)