In this snippet, f
is a function taking two Double
parameters and returning a Double
.
You are attempting to call f
by passing a single argument of type Tuple2[Double,Double]
.
You can fix this by changing the type of f
in the first place:
object TestObject {
def map(f: ((Double, Double)) => Double, x2: Array[Double]) = {
val y = x2.zip( x2 )
val z = y.map(f)
z
}
}
You could also declare it as f: Tuple2[Double, Double] => Double
to be clearer (this is entirely equivalent).
Conversely, you could change your call like this:
object TestObject {
def map(f: (Double, Double) => Double, x2: Array[Double]) = {
val y = x2.zip( x2 )
val z = y.map(f.tupled)
z
}
}
tupled
automagically transforms your (Double, Double) => Double
function into a Tuple2[Double, Double] => Double
function.
Keep in mind however that the conversion will be done on each call to TestObject.map