mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
12 lines
228 B
Go
12 lines
228 B
Go
package underscore
|
|
|
|
import "errors"
|
|
|
|
func Find[T any](values []T, predicate func(T) bool) (res T, err error) {
|
|
for _, v := range values {
|
|
if predicate(v) {
|
|
return v, nil
|
|
}
|
|
}
|
|
return res, errors.New("value not found")
|
|
}
|