Fork me on GitHub

Is there a way in specter to collect values based on a predicate, pass the values to a function that updates all of them (map-like fn signature) and replace the old values with the new ones?


(defn map-replace [pred transform-all x]
  ;; ... what would go here?

(def d
  {:a 1
   :b {:c 2
       :d {:e 3}}})

(map-replace number? #(map inc %) d)
; => 
{:a 2
 :b {:c 3
     :d {:e 4}}}


of course the real world use-case is more complicated where some values of the map are I/O processes I need to run in parallel and block until all complete. this is why all of them need to be collected.