object Options extends App {
val input = args(0)
def convertToInt(input:String):Option[Int]=input
convertToInt(input) match {
case Some(input) => println(convertToInt)
case None => println(“I should be printing nothing here”)
}
}
Options.scala:3: error: type mismatch;
found : String
required: Option[Int]
def convertToInt(input:String):Option[Int] = input
^
Options.scala:5: error: missing arguments for method convertToInt in object Options;
follow this method with `_' if you want to treat it as a partially applied function
case Some(input) => println(convertToInt)
^
two errors found
I think it’s a good idea to step back, stop fiddling with code, and start working through basic tutorials – what steps do you need to get to your result? What is it you need to do? If you can’t manage to do what you want, can you do something else, something simpler, make that work, and improve from there?
object Options extends App {
val input = args(0)
def convertToInt(x: String): Option[Int] = {
val y = Option(x.toInt)
return y
// val z = x.toInt
// if (z.isDigit) return y
}
convertToInt(input) match {
case Some(x) => println("("+x+", Int)")
case None => println(“I should be printing nothing here”)
}
}
object Options extends App {
val input = args(0)
def convertToInt(x: String): Option[Int] = {
val y = Option(x.toInt)
return y
// val z = x.toInt
// if (z.isDigit) return y
}
convertToInt(input) match {
case Some(x) => println("("+x+", Int)")
}
}
It means exactly what it says: you have a case for Some, but you don’t have a case for None. That’s usually a bug, which is why the compiler is giving you a warning. You need to add a case that handles None, however makes sense for your needs…