def stringToIntMethod(input:String):Option[Int] = {
try{
Some(Integer.parseInt(input.trim()))
}
catch{
case e:Exception => None
}
}
val stringToIntFunction: (String) => Option[Int] = (in:String) => {
try{
Some(Integer.parseInt(in.trim()))
}
catch{
case e:Exception => None
}
}
val stringAndIntArray = Array("Hello", "1","2","Hi") //Input
println("with Method is: " + stringAndIntArray.flatMap(stringToIntMethod))
println("with functon is: " + stringAndIntArray.flatMap(stringToIntFunction))
getting a type mismatch error while using stringToIntFunction in flatMap
type mismatch;
found : String => Option[Int]
required: String => scala.collection.GenTraversableOnce[?]
println("with functon is: " + stringAndIntArray.flatMap(stringToIntFunction))
^
Why is it?