Add or modify values in a shapeless HMap

徘徊边缘 提交于 2019-12-11 01:56:05

问题


Does anyone know how I might add or modify values in a shapeless HMap? The only functions I see on the HMap definition are:

  • get
  • + (which looks like it's creating a new map and adding the (k,v) tuple)
  • - (same as above)

My suspicion is that I will need to use lens?


回答1:


shapeless.HMap is immutable. It's a wrapper (with type-level enhancements) of scala.collection.immutable.Map.

+ adds or modifies a pair (returning new HMap).

Lenses also create a copy. Immutability/persistence is typical for FP.



来源:https://stackoverflow.com/questions/56346066/add-or-modify-values-in-a-shapeless-hmap

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