pub fn fold_map<'a, FnBrand, Brand: Foldable, M, A: 'a + Clone, Func>(
func: Func,
fa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> MExpand description
Maps values to a monoid and combines them.
Free function version that dispatches to the type class’ associated function.
§Type Signature
forall f m a. (Foldable f, Monoid m) => ((a) -> m, f a) -> m
§Type Parameters
FnBrand: The brand of the clonable function to use.Brand: The brand of the foldable structure.M: The type of the monoid.A: The type of the elements in the structure.Func: The type of the mapping function.
§Parameters
func: The function to map each element to a monoid.fa: The structure to fold.
§Returns
The combined monoid value.
§Examples
use fp_library::{brands::*, functions::*};
let x = Some(5);
let y = fold_map::<RcFnBrand, OptionBrand, _, _, _>(|a: i32| a.to_string(), x);
assert_eq!(y, "5".to_string());