I have this tail-recursive function that returns true if any element in the list is a Boolean
value.
def anyBoolTailRec[A](test: A=> Boolean, a: List[A]): Boolean = a match {
case Nil => false
case h :: t if(!test(h)) => anyBoolTailRec(test, t)
case _ => true
}
The test parameter is just a function to check the values type:
def isBool(i: Any) = i match {
case _: Boolean => true
case _ => false
}
The function is called like this:
anyBoolTailRec(isBool, List(1, 2, "hi", "test", false))
>>> true
Question: How can I turn this tail recursive solution into a non-tail recursive solution? Since we're returning Booleans I'm not sure how to do it.
Note: I am aware tail-recursive solutions are better in Scala.