Fork me on GitHub
#specter
<
2020-04-17
>
lvh18:04:59

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

lvh18:04:48

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