I am facing error with round brackets in high-order definition. The following code works fine:
val foo: Int => (Int => Int) = n => n + _*2
However, after adding parentheses compiler error arises
val foo1: Int => (Int => Int) = n => n + (_*2)
Error:(34, 56) missing parameter type for expanded function ((<x$5: error>) => x$5.$times(2))
I am aware that I could use another style to avoid error:
val bar = (x: Int) => (y: Int) => x + (y*2)
I interested what is the problem with parenthesis and how to use them correctly in the same style of formatting high-order functions
The first case of anonymous function placeholder parameter
expands to
whilst the second
expands to
which is a syntax error. The key is to understand the scope of underscore: