Trait par_map::ParMap [] [src]

pub trait ParMap: Iterator + Sized {
    fn par_map<B, F>(self, f: F) -> Map<Self, B, F>
    where
        F: Sync + Send + 'static + Fn(Self::Item) -> B,
        B: Send + 'static,
        Self::Item: Send + 'static
, { ... } fn par_flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
    where
        F: Sync + Send + 'static + Fn(Self::Item) -> U,
        U: IntoIterator,
        U::Item: Send + 'static,
        Self::Item: Send + 'static
, { ... } }

This trait extends std::iter::Iterator with parallel iterator adaptors. Just use it to get access to the methods:

use par_map::ParMap;

Provided Methods

Takes a closure and creates an iterator which calls that closure on each element, exactly as std::iter::Iterator::map.

The order of the elements are guaranted to be unchanged. Of course, the given closures can be executed in parallel out of order.

Example

use par_map::ParMap;
let a = [1, 2, 3];
let mut iter = a.iter().cloned().par_map(|x| 2 * x);
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), Some(6));
assert_eq!(iter.next(), None);

Creates an iterator that works like map, but flattens nested structure, exactly as std::iter::Iterator::flat_map.

The order of the elements are guaranted to be unchanged. Of course, the given closures can be executed in parallel out of order.

Example

use par_map::ParMap;
let words = ["alpha", "beta", "gamma"];
let merged: String = words.iter()
    .cloned() // as items must be 'static
    .par_flat_map(|s| s.chars()) // exactly as std::iter::Iterator::flat_map
    .collect();
assert_eq!(merged, "alphabetagamma");

Implementors