pub fn fold_map<'a, ClonableFnBrand: 'a + ClonableFn, Brand: Foldable, A: 'a + Clone, M: 'a + Monoid + Clone>(
f: ApplyFn<'a, ClonableFnBrand, A, M>,
) -> ApplyFn<'a, ClonableFnBrand, Apply0L1T<Brand, A>, M>
Expand description
Maps values to a monoid and combines them.
Free function version that dispatches to the typeclass’ associated function.
The default implementation of fold_map
is implemented in terms of fold_right
, compose
, append
and empty
where:
fold_map f = (fold_right ((compose append) f)) empty
§Type Signature
forall f a m. Foldable f, Monoid m => (a -> m) -> f a -> m
§Parameters
f
: A function that converts from values into monoidal elements.fa
: A foldable structure containing values of typeA
.
§Returns
Final monoid obtained from the folding operation.
§Examples
use fp_library::{brands::{VecBrand, RcFnBrand}, functions::{fold_map, identity}};
use std::rc::Rc;
assert_eq!(
fold_map::<RcFnBrand, VecBrand, _, String>(Rc::new(identity))(vec![
"Hello, ".to_string(),
"World!".to_string()
]),
"Hello, World!"
);