Majakovskij Majakovskij -4 years ago 177
Scala Question

In Scala, how to pass function with multiple parameter lists as an argument?

def multi_fun(i:Int, s:String)(d:Double) […]


How to pass this function now to another function as an argument, i.e. which parameter type needs to be indicated?

def fun_that_likes_multi_fun(mf:(Int, String)(Double) ⇒ Unit) […]


This would not work, fails even to parse.

Answer Source
def fun_that_likes_multi_fun(mf:(Int, String)=>Double => Unit)={}

The function you have mentioned is a curried function. Which means the result of applying the first argument list is another function that takes the second argument list to process in entirety. So it is represented as such.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download