specter

Latest version: 1.1.3
lvh 2020-04-19T18:49:15.017400Z

Subtle variant of that:

(def path-finder
  "Finds the first entry matching `pred` in a deeply nested structure of maps
  and vectors, and collects the path on the way there."
  (sr/recursive-path
   [term-pred] p
   (sr/cond-path
    (sr/pred term-pred) sr/STAY
    map? [INDEXED p]
    coll? [INDEXED-SEQ p])))
(basically the same thing but with a predicate). This works fine (as expected when selecting):
(sr/select
 (path-finder string?)
 {:a ["x"] :b {:c :d}})
;; => [[:a 0 "x"]]
But when transforming I get this unexpected behavior:
(= (sr/transform
    [(path-finder string?)]
    (fn [& path-and-val] (-> path-and-val last str/upper-case))
    {:a ["x"] :b {:c :d}})
   (sr/transform
    [NESTED-PATHS string?]
    (fn [& path-and-val] (-> path-and-val last str/upper-case))
    {:a ["x"] :b {:c :d}})
   {:a '([0 "X"]), :b {:c :d}})
Why is that zero there all of a sudden and how do I fix that?