Is it possible to 'transform' a HMap into another HMap

流过昼夜 提交于 2020-01-15 07:10:09

问题


If I have a Shapeless HMap[MappingA] (with implicits properly defined for the type MappingA[K, V]), can I type-safely transform/map it to a HMap[MappingB].

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)

来源:https://stackoverflow.com/questions/29647245/is-it-possible-to-transform-a-hmap-into-another-hmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!