foldMap<A, M> function

M Function(Identity<A>) foldMap<A, M>(
  1. BaseMonoid<M> monoid,
  2. M f(
    1. A
    )
)

Maps over the value within an Identity monad and then folds the result using a given monoid.

This function is a combination of a map and a fold. It first applies the function f to the value wrapped in Identity and then combines it using the provided monoid's concat method.

Example:

Identity<String> id = Identity("world");
var greet = foldMap(MonoidConcat(), (s) => "Hello, " + s + "!");
print(greet(id));  // Outputs: "Hello, world!"

monoid provides the empty value and the binary concat operation for folding. f is the function that maps over the wrapped value.

Implementation

M Function(Identity<A>) foldMap<A, M>(BaseMonoid<M> monoid, M Function(A) f) =>
    (Identity<A> id) => monoid.concat(monoid.empty, f(id.value));