mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.0 KiB
1.0 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| FindIndexOf | findindexof | it/find.go#L112 | it | find |
|
https://go.dev/play/p/6TeNM7kg-r |
|
|
50 |
Searches for an element based on a predicate and returns the element, its index, and true if found. Returns zero value, -1, and false if not found.
Examples:
seq := func(yield func(int) bool) {
_ = yield(10)
_ = yield(20)
_ = yield(30)
_ = yield(40)
}
found, index, ok := it.FindIndexOf(seq, func(x int) bool {
return x > 25
})
// found == 30, index == 2, ok == true
seq := func(yield func(string) bool) {
_ = yield("apple")
_ = yield("banana")
_ = yield("cherry")
}
found, index, ok := it.FindIndexOf(seq, func(s string) bool {
return s == "orange"
})
// found == "", index == -1, ok == false