我在想这可能是无形的库。用函数替换异步匿名类
我正在使用无形来将匿名类转换为闭包。这需要使用来自FnHListerAux
特征的hlisted
。
我想要做的就是摆脱传入的虚拟函数,并返回与此函数具有相同类型签名的闭包,如F
。如果没有异步执行的匿名类,这很容易。有没有办法解决这个问题?
def async[F, A <: HList, R](
shell: Shell,
success: F,
failure: FunctionTypes.Failure,
dummy: F)(implicit h: FnHListerAux[F, A => R],
u: FnUnHListerAux[A => R, F]): F =
{ (args: A) =>
require(shell != null, "Shell cannot be null")
require(shell.getDisplay() != null, "The shell must have a display")
val display = shell.getDisplay()
display.asyncExec(new Runnable() {
def run(): Unit = {
try {
success.hlisted(args)
} catch {
case e: Throwable =>
failure(e)
}
}
})
dummy.hlisted(args)
}.unhlisted
如果你需要像这样的无意义的东西,你的算法必定会有一些严重的问题。试着解释你需要什么。 – 2012-07-18 00:45:26
当然,这是一个好主意。我对Scala很陌生。我仍然很好奇,看看你是否真的可以取代一个函数的主体。但是,对于我的实际问题,解决方案很可能存在于不成形的图书馆中,这超出了我的知识水平,我仍然试图理解它的本质。 – Hakkar 2012-07-18 00:58:03