To read input from a user, we use the readLine function that’s in the scala.io.StdIn data type. Again — imagining that we’re reading input in a REST service — we know that we want to return a Try:
def readInput(): Try
Because readLine returns a String, the function returns a Try[String], and the complete function looks like this:
def readInput(): Try[String] = Try {
StdIn.readLine()
}