Use Specter to transform Clojure’s lists

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

Interesting:

To change the name of all the stations named “Barista” to “Coffee Master”, I can use a for comprehension:

(for [site sites station (:stations site)]
  (if (= (:name station) "Barista")
    (assoc station :name "Coffee Master")
    station))

But using Specter:

(->> sites (transform [ALL :stations ALL #(= (:name %) "Barista")]
     #(assoc % :name "Coffee Master")))

Now, this example is not actually doing justice to Specter. But in a previous (superseded) versions of the system, Specter replaced what would have been some really hairy logic with a two lines of code. I expect to be using it more in the future.

Source