How can I create an anonymous and curried function in Scala? The following two failed:
scala> (x:Int)(y:Int) => x*y
<console>:1: error: not a legal formal parameter
(x:Int)(y:Int) => x*y
^
scala> ((x:Int)(y:Int)) => x*y
<console>:1: error: not a legal formal parameter
((x:Int)(y:Int)) => x*y
^
To create a curried function write it as if it were multiple functions (that’s actually the case 😉 ).
This means you have a function from Int to a function from Int to Int.
alternatively you can write it like this: