Files
lo/docs/data/it-findlastindexof.md
T
2025-10-08 19:35:53 +02:00

1.1 KiB

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
FindLastIndexOf findlastindexof it/find.go#L127 it find
func FindLastIndexOf[T any](collection iter.Seq[T], predicate func(item T) bool) (T, int, bool)
https://go.dev/play/p/7UfON8lh-s
it#find#findlastindexof
core#slice#findlastindexof
it#find#findindexof
it#find#find
60

Searches for the last element matching 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(20)
    _ = yield(40)
}
found, index, ok := it.FindLastIndexOf(seq, func(x int) bool {
    return x == 20
})
// found == 20, index == 3, ok == true
seq := func(yield func(string) bool) {
    _ = yield("apple")
    _ = yield("banana")
    _ = yield("cherry")
}
found, index, ok := it.FindLastIndexOf(seq, func(s string) bool {
    return len(s) > 10
})
// found == "", index == -1, ok == false