Skip to content

Commit e2d7adc

Browse files
committed
Specialize Inspect's folds
1 parent e9537f9 commit e2d7adc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,19 @@ where
11871187
fn size_hint(&self) -> (usize, Option<usize>) {
11881188
self.it.size_hint()
11891189
}
1190+
1191+
#[inline]
1192+
fn fold<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1193+
where
1194+
Self: Sized,
1195+
Fold: FnMut(Acc, &Self::Item) -> Acc,
1196+
{
1197+
let mut f = self.f;
1198+
self.it.fold(init, |acc, item| {
1199+
f(item);
1200+
fold(acc, item)
1201+
})
1202+
}
11901203
}
11911204

11921205
impl<I, F> DoubleEndedStreamingIterator for Inspect<I, F>
@@ -1199,6 +1212,19 @@ where
11991212
(self.f)(item);
12001213
}
12011214
}
1215+
1216+
#[inline]
1217+
fn rfold<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
1218+
where
1219+
Self: Sized,
1220+
Fold: FnMut(Acc, &Self::Item) -> Acc,
1221+
{
1222+
let mut f = self.f;
1223+
self.it.rfold(init, |acc, item| {
1224+
f(item);
1225+
fold(acc, item)
1226+
})
1227+
}
12021228
}
12031229

12041230
/// A streaming iterator which transforms the elements of a streaming iterator.

0 commit comments

Comments
 (0)