Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure set of maps - basic filtering

Tags:

clojure

Clojure beginner here..

If I have a set of maps, such as

 (def kids #{{:name "Noah" :age 5}
     {:name "George":age 3}
     {:name "Reagan" :age 1.5}})  

I know I can get names like this

  (map :name kids)

1) How do I select a specific map? For example I want to get back the map where name="Reagan".

 {:name "Reagan" :age 1.5}

Can this be done using a filter?

2) How about returning the name where age = 3?

like image 806
Rob Buhler Avatar asked Dec 08 '22 22:12

Rob Buhler


1 Answers

Yes, you can do it with filter:

(filter #(= (:name %) "Reagan") kids)

(filter #(= (:age %) 3) kids)
like image 195
ffriend Avatar answered Jan 18 '23 19:01

ffriend