As usual in Scala, there is another way to achieve what you want to do.
Here is an example based on currying the first argument along with compose
of Function1
:
def fun1(x : Int)(y : Int) = x def fun2(x : Int)(foo : Map[Int, String], bar : Seq[Seq[Int]]) = x def modify(x : Int) = 2*x
Result types like REPL indicate that you will:
fun1: (x: Int)(y: Int)Int fun2: (x: Int)(foo: Map[Int,String], bar: Seq[Seq[Int]])Int modify: (x: Int)Int
And instead of wrapping the functions fun1
and fun2
, you compose
them, as technically, they are now objects of Function1
. This allows you to make calls such as:
(fun1 _ compose modify)(2)(5) (fun2 _ compose modify)(2)(Map(), Seq())
Both of them will return 4. Of course, the syntax is not so good, considering that you need to add _
to distinguish the fun1
application from the function object itself (on which you want to call compose
in this case).
So, Luigi’s argument that this is impossible at all remains valid, but if you are free to perform your functions, you can do it in such a good way.
source share