fold_map

Function fold_map 

Source
pub fn fold_map<'a, Brand: Foldable, A: 'a + Clone, M, F>(
    f: F,
    fa: Apply1L1T<'a, Brand, A>,
) -> M
where M: Monoid + 'a, F: Fn(A) -> M + 'a,
Expand description

Maps values to a monoid and combines them.

Free function version that dispatches to the type class’ associated function.

§Type Signature

forall a m. (Foldable t, Monoid m) => ((a) -> m, t a) -> m

§Parameters

  • f: The function to map each element to a monoid.
  • fa: The structure to fold.

§Returns

The combined monoid value.

§Examples

use fp_library::classes::foldable::fold_map;
use fp_library::brands::OptionBrand;
use fp_library::types::string; // Import Monoid impl for String

let x = Some(5);
let y = fold_map::<OptionBrand, _, _, _>(|a: i32| a.to_string(), x);
assert_eq!(y, "5".to_string());