I am faced with the following problem: I want to be able to modify a mathematical function in a way that you would move it in an x-y-graph. Therefore, I have two variables, x and y, which shall move the function upwards or to the right, respectively.
Let f
be a function of type Double => Double
, and let x
and y
be the aforementioned parameters. I want to do this:
def moveGraph(f: Double => Double, x: Double, y: Double): Double => Double = {
f(_ - x) + y
}
This, however, throws the following compiler error:
Error:(5, 7) missing parameter type for expanded function ((x$1) => x$1.$minus(x))
f(_ - x) + y
^
How can I have _
represent the parameter put into the function passed as f
and still operate on it?