Skip to main content

FoldMapDispatch

Trait FoldMapDispatch 

Source
pub trait FoldMapDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, A: 'a, M, FA, Marker> {
    // Required method
    fn dispatch(self, fa: FA) -> M;
}
Expand description

Trait that routes a fold_map operation to the appropriate type class method.

Fn(A) -> M resolves to Val, Fn(&A) -> M resolves to Ref. The FA type parameter is inferred from the container argument: owned for Val dispatch, borrowed for Ref dispatch.

§Type Parameters

  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • Brand: The brand of the foldable structure.
  • A: The type of the elements.
  • M: The monoid type.
  • FA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically.

Required Methods§

Source

fn dispatch(self, fa: FA) -> M

Perform the dispatched fold_map operation.

§Type Signature

(self, FA) -> M

§Parameters
  • self: The closure implementing this dispatch.
  • fa: The structure to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let result = fold_map::<RcFnBrand, VecBrand, _, _, _, _>(|a: i32| a.to_string(), vec![1, 2, 3]);
assert_eq!(result, "123");

Implementors§

Source§

impl<'a, 'b, FnBrand, Brand, A, M, F> FoldMapDispatch<'a, FnBrand, Brand, A, M, &'b <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Ref> for F
where Brand: RefFoldable, FnBrand: LiftFn + 'a, A: Clone + 'a, M: Monoid + 'a, F: Fn(&A) -> M + 'a,

Routes Fn(&A) -> M closures to RefFoldable::ref_fold_map.

The container must be passed by reference (&fa).

§Type Parameters
  • 'a: The lifetime.
  • 'b: The borrow lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The foldable brand.
  • A: The element type.
  • M: The monoid type.
  • F: The closure type.
Source§

impl<'a, FnBrand, Brand, A, M, F> FoldMapDispatch<'a, FnBrand, Brand, A, M, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for F
where Brand: Foldable, FnBrand: LiftFn + 'a, A: 'a + Clone, M: Monoid + 'a, F: Fn(A) -> M + 'a,

Routes Fn(A) -> M closures to Foldable::fold_map.

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The foldable brand.
  • A: The element type.
  • M: The monoid type.
  • F: The closure type.