Skip to content

Commit 647228e

Browse files
add fold and fold_mut
1 parent e5d6e41 commit 647228e

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
@@ -1324,6 +1324,16 @@ where
13241324
fn get(&self) -> Option<&Self::Item> {
13251325
self.iter.get().and_then(|iter| iter.get())
13261326
}
1327+
1328+
#[inline]
1329+
fn fold<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1330+
where
1331+
Self: Sized,
1332+
Fold: FnMut(Acc, &Self::Item) -> Acc,
1333+
{
1334+
self.iter
1335+
.fold_mut(init, |acc, item| item.fold(acc, &mut fold))
1336+
}
13271337
}
13281338

13291339
impl<I, J> StreamingIteratorMut for Flatten<I>
@@ -1335,6 +1345,16 @@ where
13351345
fn get_mut(&mut self) -> Option<&mut Self::Item> {
13361346
self.iter.get_mut().and_then(J::get_mut)
13371347
}
1348+
1349+
#[inline]
1350+
fn fold_mut<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1351+
where
1352+
Self: Sized,
1353+
Fold: FnMut(Acc, &mut Self::Item) -> Acc,
1354+
{
1355+
self.iter
1356+
.fold_mut(init, |acc, item| item.fold_mut(acc, &mut fold))
1357+
}
13381358
}
13391359

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

0 commit comments

Comments
 (0)