If you apply the map
method to a list of tuples in Scala, it complains of an error, as shown below:
scala> val s = List((1,2), (3,4)) s: List[(Int, Int)] = List((1,2), (3,4)) scala> s.map((a,b) => a+b) <console>:13: error: missing parameter type Note: The expected type requires a one-argument function accepting a 2-Tuple. Consider a pattern matching anonymous function, `{ case (a, b) => ... }` s.map((a,b) => a+b) ^ <console>:13: error: missing parameter type s.map((a,b) => a+b)
But if I apply a similar map
method to an Int list, it works fine:
scala> val t = List(1,2,3) t: List[Int] = List(1, 2, 3) scala> t.map(a => a+1) res14: List[Int] = List(2, 3, 4)
Does anyone know why this is so? Thanks.
source share