Scala, Composing Function with two values
scala
Solution
You're attempting to compose a Function2 (adder) with a Function1, hence the issue. One workaround is to change your definition of Adder to a curried version:
def adder(a: Int)(b: Int):Int = a + b
Then doubleAdd to partially apply adder like this:
def doubleAdd(x: Int) = doubler _ compose adder(x)
What's happening under the hood is transforming adder from a `Function2 (Int, Int) => Int`, to a `Function1 (Int) => (Int) => Int`, or a function that returns a function. You're then able to compose the function returned from adder with the first parameter already applied.
Problem
``` def adder(a:Int,b:Int):Int = {a+b} def doubler(a:Int):Int = {a*2} def doubleAdd = doubler _ compose adder ``` I get the error: type mismatch found: (Int,Int)=>Int required: ? => Int Then if I just try doubleAdd = doubler(adder _) I get the same error except required Int instead of ? => Int Is there a way of composing a function with two parameters? Sorry if this is pretty basic, I'm pretty new to the language, and I couldn't find an example with two parameters anywhere.