简体   繁体   English

Clojure从地图向量中提取值

[英]Clojure extracting the values from the vector of maps

Is there a way to extract all the values from a vector of maps? 有没有办法从地图矢量中提取所有值?

(def vector-of-maps [{:a 1 :b 2} {:a 3 :b 4}])

Because 因为

(vals vector-of-maps)

doesn't work of course. 当然行不通。

I am trying to apply a function on every map in a vector, therefore I need every map, ie. 我试图在向量中的每个地图上应用一个函数,因此我需要每个地图。 {:a 1 :b 2}, and then {:a 3 :b 4} {:a 1:b 2},然后{:a 3:b 4}

尝试这个:

(mapcat vals vector-of-maps)

This would do. 这样就可以了。 Because maps are not ordered, you might see the values in different order than in the literal map representation: 由于地图未排序,因此您可能会看到与文字地图表示形式不同的值顺序:

(mapcat vals vector-of-maps)

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

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