Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename keys in sequence of maps in clojure

Tags:

clojure

I have the following structure

(def aaa '({:a "read" :b "one"} {:a "open" :b "two"}) )

I need to rename all :a keys for example to :c and I want to get

({:c "read" :b "one"} {:c "open" :b "two"})
like image 978
Maxx Avatar asked Jul 01 '16 12:07

Maxx


1 Answers

You are looking for clojure.set's rename-keys function. Used with map, you'll get the result you want:

(map #(clojure.set/rename-keys % {:a :c}) [{:a "read" :b "one"} {:a "open" :b "two"}])
=> ({:b "one", :c "read"} {:b "two", :c "open"})
like image 198
Krisztián Szabó Avatar answered Nov 03 '22 20:11

Krisztián Szabó