Fork me on GitHub
#specter
<
2022-01-28
>
denik20:01:33

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?

denik20:01:14

(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}}}

denik20:01:00

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.