使用 productElements 将元组转换为 HList [英] Tuple to HList using productElements

查看:36
本文介绍了使用 productElements 将元组转换为 HList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Shapeless 2.2.5.我尝试使用以下代码将元组转换为 HList.

I am using Shapeless 2.2.5. I try to convert a tuple to HList using the code below.

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

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

但我收到一个编译错误.

But I get a compilation error.

[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

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

The test conversions.scala in https://github.com/milessabin/shapeless/blob/master/core/src/test/scala/shapeless/conversions.scala

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

did not provide an implicit value for Generic[(Int,String,Double,Boolean)].

我错过了一些进口吗?

在此先感谢您的帮助!

推荐答案

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

It should be import syntax.std.tuple._ rather than import syntax.std.product._.

这篇关于使用 productElements 将元组转换为 HList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆