(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))
Yeah, for such cases you can simply write a recursive function instead of using specter, or combine specter with a recursive helper function.
The only downside is it would also transform a vector whose first element is :c as well
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.
well, I think I finally managed to get Specter working in cljs bootstrap: https://github.com/redplanetlabs/specter/issues/72