我有一系列地图。将地图序列转换为多地图
;; input
[{:country "MX", :video 12345, :customer "cid1"}
{:country "US", :video 12345, :customer "cid2"}
{:country "MX", :video 54321, :customer "cid1"}]
我想将它转换成一个multimap。我想生成。
;; output
{"cid1"
{:actions
[{:country "MX", :video 12345, :customer "cid1"}
{:country "MX", :video 12345, :customer "cid1"}]},
"cid2"
{:actions
[{:country "US", :video 12345, :customer "cid2"}]}}
我觉得我应该使用update-in
。有些事情......我只是没有弄清楚some-fn-here
的样子,我想其他人可能会有同样的问题。
(defn add-mm-entry
[m e]
(update-in m [(:customer e)] some-fn-here))
(def output (reduce add-mm-entry {} input))
想象一下,当我工作时,我会把它扔给社区。如果我在这里走错了路,让我知道。
最终输出应该是一张地图,所以你需要通过'(到{})'运行结果。 –