specter

Latest version: 1.1.3
Lucy Wang 2020-10-14T03:38:39.015300Z

(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 Wang 2020-10-14T12:15:07.016100Z

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

Lucy Wang 2020-10-14T03:38:44.015500Z

@cjmurphy

Lucy Wang 2020-10-14T04:17:43.015600Z

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

cjmurphy 2020-10-14T06:32:56.015800Z

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 @wxitb2017.

2020-10-14T19:34:51.016600Z

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

1