本文介绍了在无形状的HMap中添加或修改值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我如何在无形状的HMap中添加或修改值吗?我在HMap定义上看到的唯一功能是:

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
  • +(看起来正在创建新地图并添加(k,v)元组)
  • -(与上面相同)
  • 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?

推荐答案

shapeless.HMap是不可变的.它是scala.collection.immutable.Map的包装(具有类型级别的增强功能).

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

+添加或修改一对(返回新的HMap).

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

镜头也会创建一个副本.不变性/持久性是FP的典型特征.

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

这篇关于在无形状的HMap中添加或修改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 20:12