fold<A, B> function

B Function(Identity<A>) fold<A, B>(
  1. B initial,
  2. B f(
    1. B,
    2. A
    )
)

Folds the value within an Identity monad.

Applies a binary function f to the initial value and the value wrapped in the Identity. This function is useful for combining the wrapped value with another value.

Example:

Identity<int> id = Identity(5);
var sum = fold(10, (accum, value) => accum + value);
print(sum(id));  // Outputs: 15

initial is the initial accumulator value. f is the binary function that takes the accumulator and the value wrapped in Identity as arguments.

Implementation

B Function(Identity<A>) fold<A, B>(B initial, B Function(B, A) f) =>
    (Identity<A> m) => f(initial, m.value);