如何写A :: B :: C => D给出A :: B :: C和(A,B,C)=> d?

时间:2015-03-02 07:54:10

标签: scala shapeless

假设我有HList类型A :: B :: C和函数(A, B, C) => D。如何以最简单和最惯用的方式编写函数A :: B :: C => D

1 个答案:

答案 0 :(得分:4)

toProduct中有方法syntax.std.function

import shapeless._
import syntax.std.function._
def testf(d: Double, l: Long, i: Int): String = s"$d, $l, $i"

(testf _).toProduct
// Double :: Long :: Int :: HNil => String = <function1>

请参阅Feature overview: shapeless 2.0.0/Facilities for abstracting over arity