concatAll<T> function
- BaseMonoid<
T> monoid
Returns a function that takes a list of type T and concatenates all elements in the list using the monoid
Example:
void main() {
// Create a monoid for integer addition with identity element 0
BaseMonoid<int> monoid = SemigroupSum() as BaseMonoid<int>;
// Concatenate a list of integers using the monoid
List<int> numbers = [1, 2, 3, 4, 5];
int sum = concatAll(monoid)(numbers); // Output: 15 (1 + 2 + 3 + 4 + 5)
}
Implementation
T Function(List<T>) concatAll<T>(BaseMonoid<T> monoid) {
return (List<T> as) =>
as.fold(monoid.empty, (acc, a) => monoid.concat(acc, a));
}