Shapeless-Ydependent-method-types
需要依赖方法类型(基于此单元测试,它将适用于您的案例,如下所示:
import shapeless.Tuples._
import shapeless.HList._
val t7 = (t1.hlisted ::: t2.hlisted ::: t3.hlisted).tupled
尽管 Miles 表示不保证支持,但它实际上有单元测试,并且源代码在 github 上,具有开源许可证,因此至少它不仅仅是博客文章中的实验。
编辑:像广告一样工作-编译需要一些时间,我不得不添加-Xss1m
到 sbt:
$ scala -Ydependent-method-types -cp target/scala-2.9.1/shapeless_2.9.1-1.1.0.jar
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.7.0).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless.Tuples._
import shapeless.Tuples._
scala> import shapeless.HList._
import shapeless.HList._
scala> val t1 = Tuple2("abcd", "efg")
t1: (java.lang.String, java.lang.String) = (abcd,efg)
scala> val t2 = Tuple2(1234, "lmnop")
t2: (Int, java.lang.String) = (1234,lmnop)
scala> val t3 = Tuple3("qrs", "tuv", "wxyz")
t3: (java.lang.String, java.lang.String, java.lang.String) = (qrs,tuv,wxyz)
scala> (t1.hlisted ::: t2.hlisted ::: t3.hlisted).tupled
res0: (java.lang.String, java.lang.String, Int, java.lang.String, java.lang.String,
java.lang.String, java.lang.String) = (abcd,efg,1234,lmnop,qrs,tuv,wxyz)