Assume we have Object that takes function as parameter of apply
method:
object Wrapper {
def apply(block: TypeA => String) = {
TypeA a = ...
block(a)
}
}
TypeA
is domain type of application.
Now when I define inline block I can define TypeA
parameter as implicit:
Wrapper { implicit a => functionThatUseImplicitA() }
But what if block
parameter is not Function1
, but Function2
? How can I define both parameters as implicit?
object Wrapper2 {
def apply(block: (TypeA, TypeB) => String) = {
TypeA a = ...
TypeB b = ...
block(a, b)
}
}
This one does not work:
Wrapper { implicit (a, b) => functionThatUseImplicitAB() }
The only workaround is define them as vals:
Wrapper { (a, b) =>
implicit val ia = a
implicit val ib = b
functionThatUseImplicitAB()
}
Thanks!