Skip to main content

ParRefFoldable

Trait ParRefFoldable 

Source
pub trait ParRefFoldable: RefFoldable + Kind_cdc7cd43dac7585f {
    // Required method
    fn par_ref_fold_map<'a, A: Send + Sync + 'a, M: Monoid + Send + 'a>(
        f: impl Fn(&A) -> M + Send + Sync + 'a,
        fa: &Self::Of<'a, A>,
    ) -> M;
}
Expand description

Parallel by-reference folding over a structure.

Maps each element by reference to a monoid using a Send + Sync function and combines the results. When the rayon feature is enabled, elements are processed across multiple threads.

Required Methods§

Source

fn par_ref_fold_map<'a, A: Send + Sync + 'a, M: Monoid + Send + 'a>( f: impl Fn(&A) -> M + Send + Sync + 'a, fa: &Self::Of<'a, A>, ) -> M

Maps each element by reference to a monoid and combines them in parallel.

§Type Signature

forall A M. Monoid M => (&A -> M, &Self A) -> M

§Type Parameters
  • 'a: The lifetime of the elements.
  • A: The element type.
  • M: The monoid type.
§Parameters
  • f: The function to map each element reference to a monoid. Must be Send + Sync.
  • fa: The structure to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::{
	brands::VecBrand,
	classes::par_ref_foldable::ParRefFoldable,
};

let v = vec![1, 2, 3];
let result = VecBrand::par_ref_fold_map(|x: &i32| x.to_string(), &v);
assert_eq!(result, "123");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§