Skip to content

Commit 0410bca

Browse files
committed
Specialize ProcessResults::fold
1 parent a139571 commit 0410bca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/process_results_impl.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ impl<'a, I, T, E> Iterator for ProcessResults<'a, I, E>
3030
fn size_hint(&self) -> (usize, Option<usize>) {
3131
(0, self.iter.size_hint().1)
3232
}
33+
34+
fn fold<B, F>(mut self, init: B, mut f: F) -> B
35+
where
36+
Self: Sized,
37+
F: FnMut(B, Self::Item) -> B,
38+
{
39+
let error = self.error;
40+
self.iter
41+
.try_fold(init, |acc, opt| match opt {
42+
Ok(x) => Ok(f(acc, x)),
43+
Err(e) => {
44+
*error = Err(e);
45+
Err(acc)
46+
}
47+
})
48+
.unwrap_or_else(|e| e)
49+
}
3350
}
3451

3552
/// “Lift” a function of the values of an iterator so that it can process

0 commit comments

Comments
 (0)