Skip to content

Commit 5d2bbcc

Browse files
committed
Merge #497
497: impl FromParallelIterator<()> for () r=cuviper a=cuviper This is more useful when combined with higher-level abstractions, like collecting to a `Result<(), E>` where you only care about errors. This is a parallel version of rust-lang/rust#45379. Cc #496
2 parents f37fc75 + 28ca2e4 commit 5d2bbcc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/iter/from_par_iter.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{FromParallelIterator, IntoParallelIterator, ParallelExtend};
1+
use super::{FromParallelIterator, IntoParallelIterator, ParallelIterator, ParallelExtend};
22

33
use std::borrow::Cow;
44
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
@@ -170,3 +170,26 @@ impl<'a, C: ?Sized, T> FromParallelIterator<T> for Cow<'a, C>
170170
Cow::Owned(C::Owned::from_par_iter(par_iter))
171171
}
172172
}
173+
174+
/// Collapses all unit items from a parallel iterator into one.
175+
///
176+
/// This is more useful when combined with higher-level abstractions, like
177+
/// collecting to a `Result<(), E>` where you only care about errors:
178+
///
179+
/// ```
180+
/// use std::io::*;
181+
/// use rayon::prelude::*;
182+
///
183+
/// let data = vec![1, 2, 3, 4, 5];
184+
/// let res: Result<()> = data.par_iter()
185+
/// .map(|x| writeln!(stdout(), "{}", x))
186+
/// .collect();
187+
/// assert!(res.is_ok());
188+
/// ```
189+
impl FromParallelIterator<()> for () {
190+
fn from_par_iter<I>(par_iter: I) -> Self
191+
where I: IntoParallelIterator<Item = ()>
192+
{
193+
par_iter.into_par_iter().for_each(|()| {})
194+
}
195+
}

0 commit comments

Comments
 (0)