小编Shi*_*ing的帖子

使用 productElements 将元组转换为 HList

我正在使用 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)] 提供隐式值。

我错过了一些进口吗?

在此先感谢您的帮助!

shapeless

3
推荐指数
1
解决办法
1450
查看次数

如何在phantom-dsl中连续更新多个字段?

我正在使用 Phantom 1.26.6。

// id is the primary key
case class Motorcycle(id:String, model:String, made:String, capacity:Int)
Run Code Online (Sandbox Code Playgroud)

举一个已经存在于Cassandra中的Motorcycle实例,我想更新model、made、capacity的值。

// The following does not compile.
 update.where(_.id.eqs(bike.id)).modify(_.model.setTo(bike.model))
 .modify(_.make.setTo(bike.make))
 .modify(_.capacity.setTo(bike.capacity))


 // The following works.   
 val updateQuery = update.where(_.id.eqs(bike.id))

 for {
    _ <- updateQuery.modify(_.model.setTo(bike.model)).future()
    _ <- updateQuery.modify(_.make.setTo(bike.made)).future()
    result <- updateQuery.modify(_.capacity.setTo(bike.capacity)).future()
  } yield (result)
Run Code Online (Sandbox Code Playgroud)

我想知道是否有更好的方法来更新多个字段。

在此先感谢您的帮助!

scala cassandra phantom-dsl

3
推荐指数
1
解决办法
752
查看次数

标签 统计

cassandra ×1

phantom-dsl ×1

scala ×1

shapeless ×1