In scala REPL, this works well
scala> (1 to 3).foreach(i => print(i + ","))
1,2,3,
But this won't work
scala> (1 to 3).foreach(print(_ + ","))
<console>:8: error: missing parameter type for expanded function ((x$1) => x$1.$plus(","))
(1 to 3).foreach(print(_ + ","))
If I remove the +","
part, it works again:
scala> (1 to 3).foreach(print(_ ))
123
I think the (1 to 3).foreach(print(_ + ","))
might work because there is only one parameter, which is _
. Why does scala complain about this?