apply()
後に明示的な呼び出しが必要な理由を誰かが説明してもらえますかmap()
scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)
scala> l(2)
res56: Int = 3
scala> l.map(x => x*2)
res57: List[Int] = List(2, 4, 6)
scala> l.map(x => x*2)(2)
<console>:9: error: type mismatch;
found : Int(2)
required: scala.collection.generic.CanBuildFrom[List[Int],Int,?]
l.map(x => x*2)(2)
^
scala> l.map(x => x*2).apply(2)
res59: Int = 6
ありがとう。