I'm trying to write a function that returns another function based on a string input. I think I want matchfun("X") to be a (Double, Double) => Double:
def matchfun(foo: String) = {
foo match {
case "X" => (x: Double, y: Double) => x + y
case "Y" => (x: Double) => x + 2
case "Z" => (x: Double, y: Double) => x * y
}
}
matchfun("X")
matchfun("X")(1,2)
matchfun: (foo: String)Object
res116: Object = <function2>
<console>:173: error: Object does not take parameters
matchfun("X")(1,2)
^
Objectthat doesn't have apply() method. I need to understand your use case in order to change your code design.foohere would represent the distribution family, and since distributions have different number of parameters their deviance functions have different domains.