What's the better form for double arguments function value?

scala> val f:(String,String) => String = (s1,s2) => s1+s2
val f: (String, String) => String = $Lambda$1155/0x00000008010c8220@3ec211cc

scala> f("helo"," world")
val res6: String = helo world

scala> val g: String => String => String = s1 => s2  => s1+s2
val g: String => (String => String) = $Lambda$1162/0x00000008010c9c70@4b808427

scala> g("helo")("world")
val res9: String = heloworld

which one is used more widely in practical?

Thanks

Neither, the most common one would be:

def f(s1: String, s2: String): String = s1 + s2

Or, if you know you will partially apply it a lot then:

def f(s1: String)(s2: String): String = s1 + s2

A direct function are only used when you know you need it to be a function most of the time; in such case, the non-curried form is probably more common.

2 Likes