-
Notifications
You must be signed in to change notification settings - Fork 335
Open
Description
This is similar to partition_result
.
The idea is that instead of a collection of Ok
values and a collection of Err
values, it would return a single Result
.
This is ideal for situations where you want to report all errors (not short-circuiting), and the Ok
values only matter if there are no errors.
The implementation is below:
fn single_result<A, B, T, E>(self) -> Result<A, B>
where
Self: Iterator<Item = Result<T, E>> + Sized,
A: Default + Extend<T>,
B: Default + Extend<T>,
{
let mut is_err = false;
let (a, b): (A, B) = self.partition_map(|r| match r {
Ok(v) => Either::Left(v),
Err(v) => {
is_err = true;
Either::Right(v)
},
});
if is_err {
Err(b)
} else {
Ok(a)
}
}
Thank you for your time and consideration.
Metadata
Metadata
Assignees
Labels
No labels