Just like this:
def multiFun(i:Int, s:String)(d:Double):Unit = ???
def highOrderFun(mF:(Int, String) => Double => Unit) = ???
highOrderFun(multiFun)
Think of multiFun
as of function that takes (Int, String)
and returns function with type Double => Unit
.
Upd: Regarding implicit parameters. It seems that it's not possible to pass a method with implicit parameters as is. See some details here. Although I can see nice workaround for your case:
def multiFun(i:Int, s:String)(implicit d:Double):Unit = ???
def highOrderFun(mF:(Int, String, Double) => Unit) = ???
highOrderFun(multiFun(_, _)(_))
This syntax multiFun(_, _)(_)
just creates wrapper function around multiFun
that takes three parameters whose types are inferred from params of multiFun
.
UPD: In response to @ackratos:
It appears that there is no way to make lambda function type generic. Mainly because there is a fundamental difference between lambda functions and methods.
But as functions above are defined as methods, nothing prevents us from making them generic:
def multiFun[T](i:T, s:String):Unit = ???
def highOrderFun[T](mF:(T, String) => Unit) = ???
highOrderFun(multiFun[Int])
It's possible to reference function that has implicit param list as function without one. In this case missing implicit params will be substituted by resolved values:
def multiFun(s:String)(implicit i:Int):Unit = ???
def highOrderFun(context:Any)(mF:String => Unit)(implicit i:Int) = ???
implicit val param = 2
highOrderFun(1.0)(multiFun) // param i:Int is resolved here