added Search function
This commit is contained in:
parent
2fb5ea542d
commit
2124bff9de
11
search.go
Normal file
11
search.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user