问题
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