Skip to main content

FoldMapWithIndexDispatch

Trait FoldMapWithIndexDispatch 

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

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

Fn(Brand::Index, A) -> M resolves to Val, Fn(Brand::Index, &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_with_index 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_with_index::<RcFnBrand, VecBrand, _, _, _, _>(
	|i, x: i32| format!("{i}:{x}"),
	vec![10, 20, 30],
);
assert_eq!(result, "0:101:202:30");

Implementors§

Source§

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

Routes Fn(Brand::Index, &A) -> M closures to RefFoldableWithIndex::ref_fold_map_with_index.

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> FoldMapWithIndexDispatch<'a, FnBrand, Brand, A, M, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for F
where Brand: FoldableWithIndex, FnBrand: LiftFn + 'a, A: 'a + Clone, M: Monoid + 'a, Brand::Index: 'a, F: Fn(Brand::Index, A) -> M + 'a,

Routes Fn(Brand::Index, A) -> M closures to FoldableWithIndex::fold_map_with_index.

§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.