使用 productElements 将元组转换为 HList

Shi*_*ing 3 shapeless

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

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

(23, "foo", 2.0, true).productElements
Run Code Online (Sandbox Code Playgroud)

但我收到编译错误。

[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
Run Code Online (Sandbox Code Playgroud)

https://github.com/milessabin/shapeless/blob/master/core/src/test/scala/shapeless/conversions.scala 中的测试转换 .scala

没有为 Generic[(Int,String,Double,Boolean)] 提供隐式值。

我错过了一些进口吗?

在此先感谢您的帮助!

Mil*_*bin 5

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