Imports System
Imports System.Collections.Generic
Imports System.Runtime.CompilerServices
Module Extensions
<Extension()>
Iterator Function IndexesWhere(Of T)(ByVal source As IEnumerable(Of T), ByVal predicate As Func(Of T, Boolean)) As IEnumerable(Of Integer)
Dim index As Integer = 0
For Each element As T In source
If predicate(element) Then
Yield index
End If
index += 1
Next
End Function
End Module
Public Class Program
Public Shared Sub Main()
Dim s As String() = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "let’s start again"}
Dim indexes = s.IndexesWhere(Function(t) t.StartsWith("t"))
Console.Write(String.Join(", ", indexes))
End Sub
End Class
' run:
'
' 2, 3, 10
'