我有一系列地圖。將地圖序列轉換爲多地圖
;; 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))
想象一下,當我工作時,我會把它扔給社區。如果我在這裏走錯了路,讓我知道。
最終輸出應該是一張地圖,所以你需要通過'(到{})'運行結果。 –