In this snippet, f is a function that takes two Double parameters and returns Double . You are trying to call f by passing one argument of type Tuple2[Double,Double] . You can fix this by changing the type f first:
object TestObject { def map(f: ((Double, Double)) => Double, x2: Array[Double]) = { val y = x2.zip( x2 ) val z = y.map(f) z } }
You can also declare it as f: Tuple2[Double, Double] => Double more understandable (this is completely equivalent).
Conversely, you can change your call as follows:
object TestObject { def map(f: (Double, Double) => Double, x2: Array[Double]) = { val y = x2.zip( x2 ) val z = y.map(f.tupled) z } }
tupled will automatically convert your function (Double, Double) => Double to the function Tuple2[Double, Double] => Double . Keep in mind that the conversion will be performed each time TestObject.map called TestObject.map
source share