If we have a method that accepts an anonymous function A => B as a parameter, we can make A implicit in our invocation.
def impl(a: Int)(f: Int => Int): Int = f(a)
impl(a) { implicit z =>
...
}
But can we do this with anonymous functions that have multiple parameters?
def impl(a: Int, b: Int)(f: (Int, Int) => Int): Int = f(a, b)
Ideally, this would work something like:
impl(1, 2) { implicit (a, b) => // wrong
...
}
Or
impl(1, 2) { (implicit a, implicit b) => // also wrong
...
}
I can work around this using A => B => C, instead:
def impl(a: Int, b: Int)(f: Int => Int => Int): Int = f(a)(b)
impl(1, 2) { implicit a => implicit b =>
...
}
But is there a way to do this without currying the functions?
It should be obvious, but Int is just a dummy placeholder here.
It is not allowed to introduce implicit parameter because of incorrect usage count of parameterA named parameter of an anonymous function may be optionally preceded by an implicit modifier. In that case the parameter is labeled implicitBut it doesn't say anything on the restriction. Its a mystery.