added Search function

This commit is contained in:
Timon Ringwald 2022-08-25 14:03:50 +02:00
parent 2fb5ea542d
commit 2124bff9de
1 changed files with 11 additions and 0 deletions

11
search.go Normal file
View File

@ -0,0 +1,11 @@
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
}