一般浓缩在scala中提供“uncurried”

时间:2012-12-11 20:45:44

标签: scala currying scalaz shapeless

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)
}

1 个答案:

答案 0 :(得分:3)

确实存在内置函数:

val foo = (x: Int) => (y: Int) => x+y
foo: Int => (Int => Int) = <function1>

Function.uncurried(foo)
res16: (Int, Int) => Int = <function2>