mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
doc: find
This commit is contained in:
parent
6c6cf9ac68
commit
dd6d077c36
1 changed files with 3 additions and 0 deletions
3
find.go
3
find.go
|
|
@ -2,6 +2,9 @@ package underscore
|
|||
|
||||
import "errors"
|
||||
|
||||
// Find looks through each value in the slice, returning the first one that passes a truth test (predicate),
|
||||
// or the default value for the type and an error if no value passes the test.
|
||||
// The function returns as soon as it finds an acceptable element, and doesn't traverse the entire slice.
|
||||
func Find[T any](values []T, predicate func(T) bool) (res T, err error) {
|
||||
for _, v := range values {
|
||||
if predicate(v) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue