val f1 = (x: Int) => x match {
case x1 => x * 2
}
val f2 = (x: Int, y: Int) => (x, y) match {
case (x1, y1) => x1 + y1
}
val f3 = f1.compose(f2)
Expecting f3 to be a partial function from (Int, Int) => Int but I get the following error
Found: (f2 : (Int, Int) => Int)
Required: Any => Int
As the documentation suggests,
composespecifically composes two instances ofFunction1, that is two instances of a unary function.If you want to keep your code as is, the way to do this is
If you look at the documentation closely
composereturns a new function f s.t.f(x) == apply(g(x))andThenreturns a new function f s.t.f(x) == g(apply(x))Note the difference in order of application. Yes, I know the naming is rather is confusing.
Edit: It is confusing which way you want these to apply. The other way around is provided in Jorg's answer.