Skip to content

Commit

Permalink
Merge #497
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors[bot] committed Jan 14, 2018
2 parents f37fc75 + 28ca2e4 commit 1f0bb74
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/iter/from_par_iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{FromParallelIterator, IntoParallelIterator, ParallelExtend};
use super::{FromParallelIterator, IntoParallelIterator, ParallelIterator, ParallelExtend};

use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
Expand Down Expand Up @@ -170,3 +170,26 @@ impl<'a, C: ?Sized, T> FromParallelIterator<T> for Cow<'a, C>
Cow::Owned(C::Owned::from_par_iter(par_iter))
}
}

/// Collapses all unit items from a parallel iterator into one.
///
/// This is more useful when combined with higher-level abstractions, like
/// collecting to a `Result<(), E>` where you only care about errors:
///
/// ```
/// use std::io::*;
/// use rayon::prelude::*;
///
/// let data = vec![1, 2, 3, 4, 5];
/// let res: Result<()> = data.par_iter()
/// .map(|x| writeln!(stdout(), "{}", x))
/// .collect();
/// assert!(res.is_ok());
/// ```
impl FromParallelIterator<()> for () {
fn from_par_iter<I>(par_iter: I) -> Self
where I: IntoParallelIterator<Item = ()>
{
par_iter.into_par_iter().for_each(|()| {})
}
}

0 comments on commit 1f0bb74

Please sign in to comment.