Write a function show using Option which returns the value of string . If inputCapital has a value show it must return the value, and if the value is None , return invalid . Print country name and capital as in the sample output format.
Hmm. I suspect the error message is misleading, and that the problem is actually that colon there. What do you expect ("India") : + capitals.get() to mean?
More generally: it’s a little hard to help you, because you aren’t formatting your code and it’s hard to read. Please, when you post code samples here, put them in code blocks. Before your code, put a line that contains just three backticks – just ``` on a line by itself – and then another one after your code. That’s absolutely essential to making your code readable, and is polite to the people trying to help. Thanks!
object Options extends App {
val input = args(0)
val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo", "India" -> "New Delhi", "Russia" -> "Moscow")
val inputCapital = capitals.get(input)
input match {
case some(x) => println(x + " : " + inputCapital)
case None => println(x + " : invalid")
}
}
Now getting error as -
$ scalac Options.scala
Options.scala:6: error: not found: value some
case some(x) => println(x + " : " + inputCapital)
^
Options.scala:7: error: pattern type is incompatible with expected type;
found : None.type
required: String
case None => println(x + " : invalid")
^
Options.scala:7: error: not found: value x
case None => println(x + " : invalid")
^
three errors found