Function value definition question

I know this works:

scala> val f9:String => String => String = x => y => x+y
val f9: String => (String => String) = $Lambda$1199/0x000000084066c040@3babb257

And this works:

scala> val f9:(String,String) => String = (x,y) => x+y
val f9: (String, String) => String = $Lambda$1208/0x000000084067f040@66ff37ff

I tried to write with another form:

scala> val f10:(String)(String) => String = (x)(y) => x+y
       error: ';' expected but '(' found.

This doesnt work.

I just want to define a function value for this kind:

scala> def mytest(x:String)(y:String) = x+y
def mytest(x: String)(y: String): String

scala> mytest("hi ")("world")
val res25: String = hi world

Can you help?
Thanks & regards

Remember that functions and methods are not the same

Multiple argument lists are a feature of methods alone, for functions you need to do what you already show in your first example, a function that returns another function.

In any case, you usually don’t need to manipulate raw functions except for lambda literals. Rather use methods and leave eta-expansion to turn them into functions when required.

1 Like