Clojure:如何合并这两个地图?
我有一个看起来像
{:a {:b {:c {:d [[1 2 3]]}
:e "Hello"}}}
{:a {:b {:c {:c {:d [4 5 6]}}}}}}
的地图。我如何合并这两个地图,以使结果看起来像这样?
{:a {:b {:c {:d [[1 2 3] [4 5 6]]}
:e "Hello"}}}
I have one map that looks like
{:a {:b {:c {:d [[1 2 3]]}
:e "Hello"}}}
and another map that looks like {:a {:b {:c {:d [[4 5 6]]}}}}
. How can I merge these two maps so that the result looks like this?
{:a {:b {:c {:d [[1 2 3] [4 5 6]]}
:e "Hello"}}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于如此简单的用例,您可以选择坚持使用Core Clojure函数:
如
R2
所示,有时我认为使用独立的闭合函数以明确显示旧的位置是更清晰的值%
正在使用。我通常更加明确,将R2闭合写为:而不是使用
#(...)
读取器宏。For such a simple use-case, you might choose to stick with core Clojure functions:
As shown for
r2
, I sometimes think it is clearer to use a self-contained closure function to explicitly show where the old value%
is being used. I am often even more explicit, writing the r2 closure as:instead of using the
#(...)
reader macro.您可以使用
deep-merge-with
来自不推荐的clojure-contrib.map-utils
:You can use
deep-merge-with
from the deprecatedclojure-contrib.map-utils
: