Files
lo/docs/data/it-indexof.md
T
2025-10-08 14:55:05 +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
IndexOf indexof it/find.go#L19 it find
func IndexOf[T comparable](collection iter.Seq[T], element T) int
it#find#indexof
core#slice#indexof
it#find#lastindexof
0

Returns the index at which the first occurrence of a value is found in the sequence, or -1 if the value is not found. Scans the sequence from the beginning and returns the position of the first matching element.

// Find existing element - returns first occurrence
seq := func(yield func(int) bool) {
    _ = yield(10)
    _ = yield(20)
    _ = yield(30)
    _ = yield(20)
}
idx := it.IndexOf(seq, 20)
// idx: 1 (first occurrence of 20)
// Element not found - returns -1
seq := func(yield func(string) bool) {
    _ = yield("apple")
    _ = yield("banana")
    _ = yield("cherry")
}
idx := it.IndexOf(seq, "orange")
// idx: -1 (orange not found in sequence)
// Empty sequence - returns -1
emptySeq := func(yield func(string) bool) {
    // no elements yielded
}
idx := it.IndexOf(emptySeq, "anything")
// idx: -1 (sequence is empty)