简体   繁体   中英

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM