Maxx
Maxx

Reputation: 163

How to rename keys in sequence of maps in 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"})

Upvotes: 5

Views: 2258

Answers (1)

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"})

Upvotes: 10

Related Questions