Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract values from vector of maps conditionally in clojure

Tags:

clojure

This code extracts all values from vector of maps.

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

so I get ("1" "2" "3" "4")

I want to get values only from :a to get ("1" "3")

What way can I do it ?

like image 769
Slava Avatar asked Dec 15 '22 07:12

Slava


1 Answers

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

yields

("1" "3")

map will apply :a as a function which will extract value from each value in vector-of-maps.

like image 109
Piotrek Bzdyl Avatar answered May 26 '23 23:05

Piotrek Bzdyl