mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
986 B
986 B
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Find | find | it/find.go#L105 | it | find |
|
https://go.dev/play/p/5SdLM6jf-q |
|
|
40 |
Searches for an element in a sequence based on a predicate function. Returns the element and true if found, zero value and false if not found.
Examples:
seq := func(yield func(int) bool) {
_ = yield(10)
_ = yield(20)
_ = yield(30)
_ = yield(40)
}
found, ok := it.Find(seq, func(x int) bool {
return x > 25
})
// found == 30, ok == true
seq := func(yield func(string) bool) {
_ = yield("apple")
_ = yield("banana")
_ = yield("cherry")
}
found, ok := it.Find(seq, func(s string) bool {
return len(s) > 10
})
// found == "", ok == false (no element longer than 10 chars)