Reputation: 131
I have a vector of maps with same keys:
(def items [{:id 1 :name "first item"}
{:id 2 :name "second item"}])
I can uppercase the value of the :name
key in the first map in the vector:
(update-in items [0 :name] clojure.string/upper-case)
=> [{:id 1, :name "FIRST ITEM"} {:id 2, :name "second item"}]
How can I uppercase every :name
key in every map? I expect this:
[{:id 1, :name "FIRST ITEM"} {:id 2, :name "SECOND ITEM"}]
Upvotes: 3
Views: 2218
Reputation: 6088
This should do it:
(map #(update-in % [:name] clojure.string/upper-case) items)
The % sign stands in for each map in items
in the function expression.
Upvotes: 3