bumped up golang version to 1.23
This commit is contained in:
12
reduce.go
12
reduce.go
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user