scala / scalaz / shapeless / etc中是否存在f: A => B => ... => Z
的一般浓缩。这样f.uncurried:(A, B, ...) => Z
?
目前我有这个,但我相信某处必须有一个预先存在的,更通用的解决方案。
implicit def enrichMyCurriedFunction[A, B, C] = new EnrichedCurriedFunction[A, B, C](_)
class EnrichedCurriedFunction[A, B, C](f: A => B => C) {
def uncurried: (A, B) => C = (a, b) => f(a)(b)
}
答案 0 :(得分:3)
确实存在内置函数:
val foo = (x: Int) => (y: Int) => x+y
foo: Int => (Int => Int) = <function1>
Function.uncurried(foo)
res16: (Int, Int) => Int = <function2>