slices/search.go
2022-08-25 14:03:50 +02:00

12 lines
194 B
Go

package slices
func Search[T any](slice []T, f func(a, b T) T) T {
if len(slice) == 0 {
return *new(T)
}
value := slice[0]
Each(slice, func(v T) { value = f(value, v) })
return value
}