Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(|()| {})
}
}