Skip to content

Commit

Permalink
Specialize ProcessResults::fold
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 committed Jul 20, 2021
1 parent 20c09bd commit d991949
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/process_results_impl.rs
Expand Up @@ -30,6 +30,23 @@ impl<'a, I, T, E> Iterator for ProcessResults<'a, I, E>
fn size_hint(&self) -> (usize, Option<usize>) {
(0, self.iter.size_hint().1)
}

fn fold<B, F>(mut self, init: B, mut f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
let error = self.error;
self.iter
.try_fold(init, |acc, opt| match opt {
Ok(x) => Ok(f(acc, x)),
Err(e) => {
*error = Err(e);
Err(acc)
}
})
.unwrap_or_else(|e| e)
}
}

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

0 comments on commit d991949

Please sign in to comment.