I want to assign an existing function to a variable. According to this site, it is as easy as:
val p = scala.math.pow(_, _)
pow: (Double, Double) => Double = <function2>
but when I try to do the same thing in my code it does not work.
def main(args: Array[String]) = {
val p = scala.math.min(_, _)
val func = if ( args(0).equalsIgnoreCase("min")) math.min(_,_) else math.max(_,_)
}
I thought this maybe due to use of if and else condition in same line, but I get error when assigning value to variable p as well.
Error I get:
missing parameter type for expanded function ((x$1, x$2) => scala.math.min(x$1, x$2))
Why does it not work for me and how can I fix it?
val p = scala.math.min _