Skip to content

Commit b407051

Browse files
committed
Add try_for_each and try_for_each_with
1 parent 3b91b55 commit b407051

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/iter/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,25 @@ pub trait ParallelIterator: Sized + Send {
365365
self.map_with(init, op).for_each(|()| ())
366366
}
367367

368+
/// TODO
369+
fn try_for_each<OP, R>(self, op: OP) -> R
370+
where OP: Fn(Self::Item) -> R + Sync + Send,
371+
R: Try<Ok = ()> + Send
372+
{
373+
self.try_fold_with((), move |(), x| op(x))
374+
.try_reduce(|| (), |(), ()| R::from_ok(()))
375+
}
376+
377+
/// TODO
378+
fn try_for_each_with<OP, T, R>(self, init: T, op: OP) -> R
379+
where OP: Fn(&mut T, Self::Item) -> R + Sync + Send,
380+
T: Send + Clone,
381+
R: Try<Ok = ()> + Send
382+
{
383+
self.map_with(init, op)
384+
.try_reduce(|| (), |(), ()| R::from_ok(()))
385+
}
386+
368387
/// Counts the number of items in this parallel iterator.
369388
///
370389
/// # Examples

0 commit comments

Comments
 (0)