このタイプのエラーを修正するにはどうすればよいですか?
object Test extends App {
def printOption[A](a: Option[A]): Option[A] = { println(a getOrElse("none")); a }
def printHashCodeAndMap[A, B](fn: Option[A] => Option[B], list: List[Option[A]]): List[Option[B]] = {
for (elem <- list) yield fn(elem.map{a => println(a.hashCode()); a})
}
val optListA = List(Some("aa"), None, Some(5))
val optListB = printHashCodeAndMap(printOption, optListA)
for (x <- optListB) printOption(x)
}
私が得るエラーは次のとおりです。
error: type mismatch;
found : Option[Nothing] => Option[Nothing]
required: Option[Any] => Option[Nothing]
val optListB = printHashCodeAndMap(printOption, optListA)