Given the following recursive function that returns Try[Int], I get a compilation error saying
type mismatch; found : scala.util.Try[Int] required: Int
But the function returns Try[Int], what is wrong? I need the function to throw an error if Try results in Failure.
def getInt(i: Int): Try[Int] = Try {
if (i == 0)
i
else {
val j = i - 1
getInt(j) // <-- error is thrown in this line
}
}