I defined a function foo like
def foo(f : (Int, Int) => Int) = f(1,2) // just calling with some default vals
and can invoke it like
foo(_+_)
But when i try to use the same way to invoke a function that takes IntPair(custom type) as param then i receive the error
error: wrong number of parameters; expected = 1
What is the correct syntax to invoke it
Sample Code
type IntPair = (Int, Int)
def sum(f: (IntPair) => Int): (IntPair) => IntPair = {
def iter(pair: IntPair): IntPair = {
val n = readLine()
print(s"$n+")
if (n != "q") {
val (total, accum) = pair
val p: IntPair = (f(n.toInt, total), accum + 1)
iter(p)
} else {
pair
}
}
iter
}
i can invoke like
val f = sum((p : IntPair) => p._1 + p._2) // i want to use here _ syntax
f((0,0))
but not like
val f = sum((_._1 + _._2)) //gives error