bumped up golang version to 1.23

This commit is contained in:
2025-06-22 19:35:57 +02:00
parent efc99a9658
commit cc2ead6c4e
11 changed files with 68 additions and 30 deletions

View File

@ -2,8 +2,8 @@ package slices
import "git.tordarus.net/tordarus/gmath"
func Reduce[T, R any](slice []T, reducer func(current R, v T) R) R {
res := new(R)
func Reduce[T, A any](slice []T, reducer Reducer[A, T]) A {
res := new(A)
Each(slice, func(v T) {
*res = reducer(*res, v)
})
@ -13,3 +13,11 @@ func Reduce[T, R any](slice []T, reducer func(current R, v T) R) R {
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)
}