Skip to main content

par_ref_map

Function par_ref_map 

Source
pub fn par_ref_map<'a, Brand: ParRefFunctor, A: Send + Sync + 'a, B: Send + 'a>(
    f: impl Fn(&A) -> B + Send + Sync + 'a,
    fa: &Brand::Of<'a, A>,
) -> Brand::Of<'a, B>
Expand description

Maps a function over a structure by reference in parallel.

Free function version that dispatches to the type class’ associated function.

§Type Signature

forall Brand A B. ParRefFunctor Brand => (&A -> B, &Brand A) -> Brand B

§Type Parameters

  • 'a: The lifetime of the elements.
  • Brand: The brand of the structure.
  • A: The input element type.
  • B: The output element type.

§Parameters

  • f: The function to apply to each element reference. Must be Send + Sync.
  • fa: The structure to map over.

§Returns

A new structure containing the mapped elements.

§Examples

use fp_library::{
	brands::VecBrand,
	functions::*,
};

let v = vec![1, 2, 3];
let result = par_ref_map::<VecBrand, _, _>(|x: &i32| x * 2, &v);
assert_eq!(result, vec![2, 4, 6]);