Fork me on GitHub
#specter
<
2020-10-14
>
Lucy Wang03:10:39

(def map-walker
    (recursive-path [] p
      (cond-path
       map?
       [ALL p]

       [vector? FIRST #(= % :c)]
       LAST

       [vector?]
       [ALL p]
       )))

(let [data {:a 1
            :b [{:z 1 :c [1 2 3]}
                {:c [{:d 1} {:e 1}]}]}]
  (transform [map-walker] #(array-map :COUNTED (count %)) data))

Lucy Wang04:10:43

The only downside is it would also transform a vector whose first element is :c as well

cjmurphy06:10:56

In reality there would never be such an element, because every vector has entities (maps) in it. Seems tricky compared to a solution not using specter. I honestly though the solution would be more straightforward than that. I just used being-counted-attributes rather than #(= % :c) , so #{:c} . Thank you @UP90Q48J3.

Lucy Wang12:10:07

Yeah, for such cases you can simply write a recursive function instead of using specter, or combine specter with a recursive helper function.

Jeff Evans19:10:51

well, I think I finally managed to get Specter working in cljs bootstrap: https://github.com/redplanetlabs/specter/issues/72

3