fold<A, B> function
- B initial,
- B f(
- B,
- 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);