如何从 var arg 列表创建 Shapeless HMap
How to create Shapeless HMap from from var arg list
我正在使用来自 scala-exercises.
的如下代码创建无形 HMap
import shapeless.HMap
class BiMapIS[K, V]
implicit val intToString = new BiMapIS[Int, String]
implicit val stringToInt = new BiMapIS[String, Int]
val hm = HMap[BiMapIS](23 -> "foo", "bar" -> 13)
我想从变量参数创建 HMap,如下所示(我有很长的参数列表,所以只是检查我是否可以简化代码 littlebit)-
import shapeless.{HMap, HNil}
import java.util.{List => JList}
val entities: JList[(_, _)] = ???
class BiMapIS[K, V]
implicit val intToString = new BiMapIS[Int, String]
implicit val stringToInt = new BiMapIS[String, Int]
import collection.JavaConverters._
val entitiesSeq = entities.asScala.toList
val hm = HMap[BiMapIS](entitiesSeq:_*)
有什么方法可以从变量 args 创建 HMap 吗?
我正在使用 shapless 2.33 和 scala 2.12 https://mvnrepository.com/artifact/com.chuusai/shapeless_2.12/2.3.3
尝试
val entitiesSeq = entities.asScala.toMap[Any, Any]
val hm = new HMap[BiMapIS](entitiesSeq)
我正在使用来自 scala-exercises.
的如下代码创建无形 HMapimport shapeless.HMap
class BiMapIS[K, V]
implicit val intToString = new BiMapIS[Int, String]
implicit val stringToInt = new BiMapIS[String, Int]
val hm = HMap[BiMapIS](23 -> "foo", "bar" -> 13)
我想从变量参数创建 HMap,如下所示(我有很长的参数列表,所以只是检查我是否可以简化代码 littlebit)-
import shapeless.{HMap, HNil}
import java.util.{List => JList}
val entities: JList[(_, _)] = ???
class BiMapIS[K, V]
implicit val intToString = new BiMapIS[Int, String]
implicit val stringToInt = new BiMapIS[String, Int]
import collection.JavaConverters._
val entitiesSeq = entities.asScala.toList
val hm = HMap[BiMapIS](entitiesSeq:_*)
有什么方法可以从变量 args 创建 HMap 吗?
我正在使用 shapless 2.33 和 scala 2.12 https://mvnrepository.com/artifact/com.chuusai/shapeless_2.12/2.3.3
尝试
val entitiesSeq = entities.asScala.toMap[Any, Any]
val hm = new HMap[BiMapIS](entitiesSeq)