是否有可能“转变”?一个HMap进入另一个HMap

时间:2015-04-15 10:01:05

标签: scala shapeless

如果我有Shapeless HMap[MappingA](为MappingA[K, V]类型正确定义了隐含),我可以输入 - 安全地将其转换/映射到HMap[MappingB]。< / p>

class MappingA[K, V]
implicit val intToString = new MappingA[Int, String]
implicit val stringToInt = new MappingA[String, Int]

class MappingB[K, V]
implicit val longToString = new MappingA[Long, String]
implicit val stringToLong = new MappingA[String, Long]

val hm1 = HMap[MappingA](1 -> "one", "two" -> 2)

// How to...
val hm2: HMap[MappingB] = ??? // transform/map hm1

// expected for hm2 in this basic example
// HMap[MappingB](1L -> "one", "two" -> 2L)

0 个答案:

没有答案