Can I turn a method which takes an implicit parameter into a function?
trait Tx
def foo(bar: Any)(implicit tx: Tx) {}
foo _ // error: could not find implicit value for parameter tx: Tx
I am trying to achieve the following, preferably if I can somehow make it work with the plain call withSelection(deleteObjects)
:
trait Test {
def atomic[A](fun: Tx => A): A
def selection: Iterable[Any]
def withSelection(fun: Iterable[Any] => Tx => Unit) {
val sel = selection
if (sel.nonEmpty) atomic { implicit tx =>
fun(sel)(tx)
}
}
object deleteAction {
def apply() {
withSelection(deleteObjects) // !
}
}
def deleteObjects(xs: Iterable[Any])(implicit tx: Tx): Unit
}
I found this question, however it does not deal with the lifting from methods to functions as far as I can see.
Implicits only work for methods. But you have to pass a function to withSelection
. You can get around by wrapping the method in a function:
withSelection(a => b => deleteObjects(a)(b))
Its impossible to pass deleteObjects
directly because foo _
does not work for a foo
with an implicit parameter list defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With