I have this polymorphic function:
def findFirst[A](as: Array[A], p: A => Boolean): Int = {
@annotation.tailrec
def loop(n: Int): Int = {
if(n >= as.length) -1
else if(p(as(n))) n
else loop(n + 1)
}
loop(0)
}
From functional programming in Scala and I want to pass the operator < Is it equal to a specific value >. How Would I do this? I currently have this:
println(findFirst(Array("abc", "def", "ghi"), == "def"))
Here the operator is < == "def">. Scala doesn't like that but I can't seem to figure out a way to pass in that value, operator pair. Something tells me currying could be used here?