1

f: A => B => ... => Z在 scala/scalaz/shapeless/etc 中是否存在一般丰富的内容?这样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)
}
4

1 回答 1

3

确实有一个内置函数:

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

Function.uncurried(foo)
res16: (Int, Int) => Int = <function2>
于 2012-12-11T20:56:42.223 回答