Search code examples
clojureclojurescriptom

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)

Solution

  • 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)