Hello.
I’ ve defined two functions with type (Int, Int) => (Int)
as follows:
def add(x: Int, y: Int): Int = x + y
def subtract(x: Int, y: Int): Int = x y
Now I would like to define a HOF which should determine if I’m passing add
or subtract
; i.e.,
def testFun(x: Int, y: Int, f: (Int, Int) => Int) = f match {
case add(a, b) => x
case subtract(a,b) => y
}
But the compiler complains that:
scala> def testFun(x: Int, y: Int, f: (Int, Int) => Int) = f match {

 case add(a, b) => x

 case subtract(a,b) => y

 }
case add(a, b) => x
^
On line 3: error: not found: value add
case subtract(a,b) => y
^
On line 5: error: not found: value subtract
I’ve tried also
def funTest: (Int, Int) => Int = {
case add(x, y) => x
case subtract(x, y) => y
}
but with the same result.
Any idea?