Clojure 的地图:键和值的顺序是否相同? [英] Clojure's maps: are keys and vals in same order?
本文介绍了Clojure 的地图:键和值的顺序是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Is it ok to rely on
(= m (zipmap (keys m) (vals m)))
in Clojure 1.3+?
Having this behavior makes for slightly more readable code in some situations, eg
(defn replace-keys [smap m]
(zipmap (replace smap (keys m)) (vals m)))
vs.
(defn replace-keys [smap m]
(into {} (for [[k v] m] [(smap k k) v]))
解决方案
I can confirm (officially) that the answer to this is yes. The docstrings for keys
and vals
were updated in Clojure 1.6 to mention this (see http://dev.clojure.org/jira/browse/CLJ-1302).
这篇关于Clojure 的地图:键和值的顺序是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文