package slices import "git.tordarus.net/tordarus/gmath" func Reduce[T, A any](slice []T, reducer Reducer[A, T]) A { res := new(A) Each(slice, func(v T) { *res = reducer(*res, v) }) return *res } func SumReducer[N gmath.Number](a, b N) N { return a + b } func MinReducer[N gmath.Number](a, b N) N { return gmath.Min(a, b) } func MaxReducer[N gmath.Number](a, b N) N { return gmath.Max(a, b) }