Currying the '+' function in scala?

I am trying to create a curried function using the + function in scala.

The ‘+’ function has 2 arguments. I want to supply create a curried function by supplying 1 parameter.

for example

def plusTwo = +(2)
plusTwo(4) //should result in 6

I am trying to create this using the + function specifically. I can do it by creating my own ‘plus’ function and then create a curried function out of it. But that is not what I am looking for.

This is not my strength, but I think that it’s important to note that the + function does not have two arguments; it is a method defined on certain classes that takes a single parameter, and adds that parameter to the value of the object on which it was called.

Could you provide some more details about what you are trying to accomplish by currying the ‘+’ function? It is likely that there is a way to accomplish your goal without writing custom ‘+’ functions.

1 Like

After just a few more minutes of thought, I believe that a partially applied function will accomplish what you want. This is one of the better explanations I’ve found regarding partially applied functions

scala> val x:Int=>Int = 2.+
x: Int => Int = $$Lambda$1065/1549840544@7a2b1eb4

scala> x(4)
res0: Int = 6

perfect. thanks:)