[英]In clojure, how can I access and return a modified version of this collection
如果我有一個這樣的集合({:A 1 :B 2 :Goal 5} {A:2 :B 4 :Goal 2})
,有一種方法可以迭代它,並使用assoc
將所有:Goal
更改為其他一些值,例如0? 因此,基本上給出了上面的集合以及鍵:Goal
該函數返回({:A 1 :B 2 :Goal 0} {A:2 :B 4 :Goal 0})
任何幫助表示贊賞。
謝謝
(let [A '({:A 1 :B 2 :Goal 5} {:A 2 :B 4 :Goal 2})]
(map #(assoc % :Goal 0) A))
或者,如果您想使用幽靈:
(let [A '({:A 1 :B 2 :Goal 5} {:A 2 :B 4 :Goal 2})]
(setval [ALL :Goal] 0 A))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.