【发布时间】:2013-05-07 08:05:53
【问题描述】:
我可以把一个带有隐式参数的方法变成一个函数吗?
trait Tx
def foo(bar: Any)(implicit tx: Tx) {}
foo _ // error: could not find implicit value for parameter tx: Tx
我正在尝试实现以下目标,如果我能以某种方式使其与普通调用 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
}
我找到了this question,但据我所知,它并没有处理从方法到函数的提升。
【问题讨论】:
标签: scala implicit currying partial-application