Questions tagged [update-in]

5 questions
5
votes
2 answers

In Clojure, How do I update a nested map correctly?

I've just started learning Clojure, after many years of Java (and PHP/JavaScript) experience. What a challenge :-) How do I update a map of values idiomatically? When I use the map function on a map it doesn't return a map, it returns a…
Steve Moseley
  • 5,797
  • 2
  • 19
  • 22
3
votes
1 answer

Update values in a vector of maps in clojure

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]…
koszti
  • 131
  • 1
  • 8
1
vote
1 answer

Is (def m (update-in m ks f & args)) a good practice?

I'm new to the world of clojure and I have a doubt. I have a nested map such as (def accounts (hash-map :XYZ (hash-map :balance (hash-map 171000 0 :171018 500 :171025 200) :statement (hash-map :171018 [{:desc…
Darakt
  • 15
  • 6
1
vote
3 answers

update two value at the same time in clojure

I am wondering how to update two values at the same time. For instance, I want to increase month and decrease age at the same time. My code is user=>(def users {:month 1 :age 26}) user=>(update-in users [:month :age] inc dec) I know this syntax is…
Xiufen Xu
  • 531
  • 1
  • 3
  • 19
0
votes
1 answer

Clojure alter update-in returns nil and dosync doesnt allow recur

EDIT: dosync creates itself a function so calls to recur get interpreted as calls made to the function dosync generated. This is the footprint of the function I actually made. Kept it as simple as possible, I think. (defn change-to-ref [ref data] …