在Clojure原子中使用交换到MERGE(附加到)嵌套映射? [英] Using swap to MERGE (append to) a nested map in a Clojure atom?
本文介绍了在Clojure原子中使用交换到MERGE(附加到)嵌套映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个包含这样的地图的原子:
{:count 0:map hash-map}
如何使用交换将另一个键值对合并到:map c> c> c> c> $ c>:
(swap!my-atom assoc-in [:map:new-key] value)
Let's say I have an atom that contains a map like this:
{:count 0 :map hash-map}
How can I use swap to merge another key-value pair onto :map
?
解决方案
You'd use assoc-in
:
(swap! my-atom assoc-in [:map :new-key] value)
这篇关于在Clojure原子中使用交换到MERGE(附加到)嵌套映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文