简体   繁体   English

根据索引合并clojure中地图的两个向量

[英]Merge two vectors of maps in clojure based on index

I have two vectors of maps in clojure, and I wish to merge them so that it is a single vector of maps, but the maps at each index are merged.我在 clojure 中有两个地图矢量,我希望将它们合并,以便它是一个单一的地图矢量,但每个索引处的地图都被合并了。 I was just wondering the best way to do this.我只是想知道最好的方法。

For example:例如:

[{:sku "e1" :name "example1"} {:sku "e2" :name "example2"}]
[{:color "Blue" :price 9.99} {:color "Red" :price 15.99}]

Would be merged to:将合并为:

[{:sku "e1" :name "example1" :color "Blue" :price 9.99} {:sku "e2" :name "example2" :color "Red" :price 15.99}]

Use mapv and merge :使用mapvmerge

(mapv merge 
      [{:sku "e1" :name "example1"} {:sku "e2" :name "example2"}]
      [{:color "Blue" :price 9.99} {:color "Red" :price 15.99}])

=> [{:sku "e1", :name "example1", :color "Blue", :price 9.99} {:sku "e2", :name "example2", :color "Red", :price 15.99}]

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

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