def findFirstA[A](arr: Array[A],target: A)(equ: (A, A) => Boolean): Int = {
def loop(idx: Int): Int = idx match {
case l if (l >= arr.length) => -1 //indicate not found
case i if (equ(arr(i),target)) => idx
case _ => loop(idx + 1)
}
loop(0)
findFirstA[String](Array("Hello","My","World"),"My")((x,y) => x == y) //> res58: Int = 1
def loop(idx: Int): Int = idx match {
case l if (l >= arr.length) => -1 //indicate not found
case i if (equ(arr(i),target)) => idx
case _ => loop(idx + 1)
}
loop(0)
}
findFirstA[String](Array("Hello","My","World"),"My")((x,y) => x == y) //> res58: Int = 1