Using FunctionX#curried

2019-08-10 12:26发布

问题:

I define foo:

scala> def foo(x: Int, y:Int): Int = x + y
foo: (x: Int, y: Int)Int

Then I failed to set bar equal to the curried function of foo.

scala> def bar = foo.curried
<console>:8: error: missing arguments for method foo;
follow this method with `_' if you want to treat it as a partially applied 
function
       def bar = foo.curried
             ^

What am I doing wrong?

回答1:

foo is not a function, it's a method. It's not an object, it has no own methods. curried is a method on object of type FunctionN.

You have to convert it to function:

(foo _).curried

With foo _ you are creating a new object of type Function2.



标签: scala