This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-17
Channels
- # announcements (1)
- # babashka (94)
- # beginners (76)
- # calva (24)
- # cider (24)
- # clj-kondo (1)
- # cljs-dev (16)
- # cljsrn (45)
- # clojure (135)
- # clojure-europe (9)
- # clojure-france (5)
- # clojure-germany (2)
- # clojure-italy (12)
- # clojure-losangeles (13)
- # clojure-nl (3)
- # clojure-portugal (54)
- # clojure-uk (20)
- # clojurescript (55)
- # conjure (67)
- # core-async (5)
- # cursive (2)
- # datomic (10)
- # docker (7)
- # duct (22)
- # emacs (16)
- # fulcro (34)
- # graalvm (15)
- # hoplon (1)
- # instaparse (1)
- # jobs-discuss (3)
- # juxt (94)
- # luminus (1)
- # meander (4)
- # off-topic (13)
- # pathom (4)
- # pedestal (1)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (61)
- # spacemacs (17)
- # specter (2)
- # sql (23)
- # xtdb (33)
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