specter

Latest version: 1.1.3
lvh 2020-04-17T18:24:59.015400Z

What I have:

(def m (-> {} (assoc-in [:a :b :c :d] 1) (assoc-in [:x :y :z] 2)))

(def INDEXED
  "A path that visits v and collects k in [[k v], ...]."
  [sr/ALL (sr/putval  sr/FIRST) sr/LAST])

(def INDEXED-SEQ
  "A selector that visits all elements of a seq, and collects their indices."
  [(sr/view #(map-indexed vector %)) INDEXED])

(def NESTED-PATHS
  (sr/recursive-path
   [] p
   (sr/cond-path
    map? [INDEXED p]
    coll? [INDEXED-SEQ p]
    sr/STAY sr/STAY)))

(sr/select [NESTED-PATHS] m)
;; => [[:a :b :c :d 1] [:x :y :z 2]]
What I would like (so I can peek/pop to destructure, since the "path" is separate from the final value):
[[[:a :b :c :d] 1] [[:x :y :z] 2]]
Of course I can just do that with last & butlast but if there was a more efficient/elegant/different version I'd love to know

lvh 2020-04-17T18:38:48.016Z

i could also solve this problem if I had a version of view that showed me the currently collected values