pub fn par_map<'a, Brand: ParFunctor, A: 'a + Send, B: 'a + Send>(
f: impl Fn(A) -> B + Send + Sync + 'a,
fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>Expand description
Maps a function over a data structure in parallel.
Applies f to each element independently. When the rayon feature is enabled,
elements are processed across multiple threads. Otherwise falls back to sequential mapping.
Free function version that dispatches to ParFunctor::par_map.
§Type Signature
forall Brand A B. ParFunctor Brand => (A -> B, Brand A) -> Brand B
§Type Parameters
'a: The lifetime of the elements.Brand: The brand of the collection.A: The input element type.B: The output element type.
§Parameters
f: The function to apply to each element. Must beSend + Sync.fa: The collection to map over.
§Returns
A new collection containing the mapped elements.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let v = vec![1, 2, 3];
let result: Vec<i32> = par_map::<VecBrand, _, _>(|x| x * 2, v);
assert_eq!(result, vec![2, 4, 6]);