使用productElements将元组转换为HList

3

我正在使用Shapeless 2.2.5。 我尝试使用以下代码将元组转换为HList。

 import shapeless._
import syntax.std.product._

(23, "foo", 2.0, true).productElements

但我遇到了编译错误。

[error] /scala/testScala/src/test/scala/lombok/shapeless/TestTuple2HList.scala:12: could not find implicit value for parameter gen: shapeless.Generic[(Int, String, Double, Boolean)]
[error]      (23, "foo", 2.0, true).productElements

https://github.com/milessabin/shapeless/blob/master/core/src/test/scala/shapeless/conversions.scala中的测试conversions.scala未提供Generic[(Int,String,Double,Boolean)]的隐式值。

我错过了一些导入吗?

非常感谢您的任何帮助!

Shing

1个回答

6

应该使用import syntax.std.tuple._而不是import syntax.std.product._


我仍然遇到相同的错误:import shapeless._ import syntax.std.tuple._ - Shing
你使用的是哪个Scala版本? - Miles Sabin
1
我真傻!我一直在使用Scala 2.10。在切换到Scala 2.11后它可以工作了。谢谢! - Shing

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接