I am trying to add some user input Strings to an immutable List with tail recursion and then add this immutable List to a MutableList which is defined.
Somehow this immutable List isn't getting prepended to my MutableList. Why is that so?
EDIT: Updated the code. Now its working!
val list = scala.collection.mutable.MutableList[String]()
def exerciseSelector() {
val user = scala.io.StdIn.readLine("go:")
user match {
case "add" => val tempList = scanInput(List[String]())
if (!tempList.isEmpty) list ++= tempList.get ; exerciseSelector()
case "print" => println(list)
case "exit" => sys.exit()
}
}
def scanInput(acc: List[String]): Option[List[String]] = {
val input = scala.io.StdIn.readLine("User input:")
input match {
case "stop" => Option(acc)
case input: String => scanInput(input :: acc)
}
}
exerciseSelector()