How can I create curried anonymous function in scala?
anonymous-function, currying, scala
Solution
To create a curried function write it as if it were multiple functions (that's actually the case ;-) ).
scala> (x: Int) => (y: Int) => x*y
res2: Int => Int => Int = <function1>
This means you have a function from Int to a function from Int to Int.
scala> res2(3)
res3: Int => Int = <function1>
alternatively you can write it like this:
scala> val f: Int => Int => Int = x => y => x*y
f: Int => Int => Int = <function1>
Problem
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 ^ ```