简体   繁体   English

Clojure中如何将地图列表转换为地图矢量?

[英]In clojure how to transform list of maps to vector of maps?

How to transform a list of maps 如何转换地图列表

(def item1 ({:tag1 "val1" ,:tag2 "val2"} {:tag1 "val3" :tag2 "val2"}))

to vector of maps. 到地图矢量。 The result should be 结果应该是

[{:tag1 "val1" ,:tag2 "val2"} {:tag1 "val3" :tag2 "val2"}]

I think what you are looking for is the vec function. 我认为您正在寻找的是vec函数。

(def item1 '({:tag1 "val1" ,:tag2 "val2"} {:tag1 "val3" :tag2 "val2"}))
(vec item1)

;= [{:tag1 "val1", :tag2 "val2"} {:tag1 "val3", :tag2 "val2"}]

Note that you were missing a quote on your list of maps, otherwise since maps can take the function position, you are applying the second map to the first one (ie (map key) ). 请注意,您在地图列表上缺少引号,否则,由于地图可以占据函数位置,因此您将第二张地图应用于第一张地图(即(map key) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM