Fork me on GitHub
#specter
<
2024-02-24
>
Coby Tamayo23:02:40

Hello, I am trying to recurse through a structure of vectors and maps. This almost does what I want, however when it finds kmod, after navigating to it I would like it to "go back" to the map it was found in and also detect krecur, and continue recuring down that path if it's there. Would be great if this were possible with recursive-path alone, but if there's a different tool for the job I would love to hear it!

(def rmapkeys (s/recursive-path
                [kmod krecur] path
                (s/cond-path
                  sequential? [s/ALL path]
                  #(get % kmod) [kmod]
                  #(get % krecur) [krecur path])))

(s/select (rmapkeys :a :b) [{:a :A
                             :b [{:a :THIS}]}
                            {:b [{:a :AA}]}])
;; actual result: [:A :AA]
;; the result I want: [:A :THIS :AA]

Coby Tamayo23:02:52

Thanks in advance 🙂