reverse<A> function
- BaseMonoid<
A> monoid
Creates a reversed version of the provided monoid
Example:
void main() {
// Create a monoid for integer addition with identity element 0
BaseMonoid<int> originalMonoid = SemigroupSum() as BaseMonoid<int>;
// Create a reversed version of the original monoid
BaseMonoid<int> reversedMonoid = reverse(originalMonoid);
// Concatenate a list of integers using the reversed monoid
List<int> numbers = [1, 2, 3, 4, 5];
int reversedSum = concatAll(reversedMonoid)(numbers); // Output: 15 (5 + 4 + 3 + 2 + 1)
}
Implementation
BaseMonoid<A> reverse<A>(BaseMonoid<A> monoid) {
return _ReverseMonoid<A>(monoid);
}