Nicolas Modrzyk
Nicolas Modrzyk

Reputation: 14197

Clojurescript Swap! and multiple assoc-in

Trying to make a piece of code better looking.

I have the following in Clojurescript:

(swap! app-state assoc-in [:lastresults] [])
(swap! app-state assoc-in [:error] false)
(swap! app-state assoc-in [:computing] true)

Sometimes more. Any idea on how to turn this in a cleaner multi-assignment.

I am looking at something like:

 (swap! app-state assoc-in
      [:lastresults] []
      [:error] false
      [:computing] true)

Upvotes: 3

Views: 844

Answers (1)

Diego Basch
Diego Basch

Reputation: 13069

You don't need assoc-in for just one level. This would work for your example:

(swap! app-state assoc 
       :lastresults [] 
       :error false 
       :computing true)

Upvotes: 7

Related Questions