Skip to content

Commit

Permalink
Add try_collect method to Itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jan 8, 2020
1 parent 505e0f4 commit 80e2e9a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -1541,6 +1541,16 @@ pub trait Itertools : Iterator {
self.collect()
}

/// `.try_collect()` is more convenient way of writing
/// `.collect::<Result<_, _>>()`
fn try_collect<T, U, E>(self) -> Result<U, E>
where
Self: Sized + Iterator<Item = Result<T, E>>,
Result<U, E>: FromIterator<Result<T, E>>,
{
self.collect()
}

/// Assign to each reference in `self` from the `from` iterator,
/// stopping at the shortest of the two iterators.
///
Expand Down

0 comments on commit 80e2e9a

Please sign in to comment.