map()
ペアのリストを呼び出したいのですが、型の不一致エラーが発生します。
たとえば、Int のペアの List をそれらの合計のリストにマップするとします。
scala> val ll=List((1,2),(3,4),(5,6))
ll: List[(Int, Int)] = List((1,2), (3,4), (5,6))
scala> ll.map((x:Int,y:Int)=>x+y)
<console>:9: error: type mismatch;
found : (Int, Int) => Int
required: ((Int, Int)) => ?
ll.map((x:Int,y:Int)=>x+y)
^
ところで、 foreach() を実行しようとすると、非常によく似たエラーが発生します。
scala> ll.foreach((x:Int,y:Int)=>println(x,y))
<console>:9: error: type mismatch;
found : (Int, Int) => Unit
required: ((Int, Int)) => ?
ll.foreach((x:Int,y:Int)=>println(x,y))
^
?
記号は何を表していますか。ここで何が欠けていますか?