-->

Add or modify values in a shapeless HMap

2019-07-14 12:38发布

问题:

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.