fold_map

Function fold_map 

Source
pub fn fold_map<'a, Brand: Foldable, A: 'a + Clone, M: Monoid<'a>>(
    f: ArcFn<'a, A, Apply0<M>>,
) -> ArcFn<'a, Apply1<Brand, A>, Apply0<M>>
where Apply0<M>: 'a + Clone,
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 type A.

§Returns

Final monoid obtained from the folding operation.

§Examples

use fp_library::{brands::{StringBrand, VecBrand}, functions::{fold_map, identity}};
use std::sync::Arc;

assert_eq!(
    fold_map::<VecBrand, _, StringBrand>(Arc::new(identity))(vec![
        "Hello, ".to_string(),
        "World!".to_string()
    ]),
    "Hello, World!"
);