Skip to main content

fold_map

Function fold_map 

Source
pub fn fold_map<'a, FnBrand, FA, A: 'a, M: Monoid + 'a, Brand>(
    func: impl FoldMapDispatch<'a, FnBrand, Brand, A, M, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
    fa: FA,
) -> M
Expand description

Maps values to a monoid and combines them, inferring the brand from the container type.

The Brand type parameter is inferred from the concrete type of fa via the InferableBrand trait. FnBrand must still be specified explicitly. Both owned and borrowed containers are supported.

For types with multiple brands, use explicit::fold_map with a turbofish.

§Type Signature

forall Brand A M. (Foldable Brand, Monoid M) => (A -> M, Brand A) -> M

§Type Parameters

  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use (must be specified explicitly).
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • A: The type of the elements.
  • M: The monoid type.
  • Brand: The brand, inferred via InferableBrand from FA and the element type.

§Parameters

  • func: The mapping function.
  • fa: The structure to fold (owned for Val, borrowed for Ref).

§Returns

The combined monoid value.

§Examples

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

let result = fold_map::<RcFnBrand, _, _, _, _>(|a: i32| a.to_string(), vec![1, 2, 3]);
assert_eq!(result, "123");