This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-05
Channels
- # announcements (9)
- # babashka (7)
- # beginners (190)
- # calva (5)
- # cider (12)
- # clara (1)
- # clj-kondo (26)
- # cljdoc (3)
- # cljsrn (5)
- # clojure (15)
- # clojure-australia (2)
- # clojure-czech (1)
- # clojure-europe (34)
- # clojure-germany (2)
- # clojure-nl (6)
- # clojure-spec (20)
- # clojure-uk (7)
- # clojurescript (6)
- # cloverage (2)
- # conjure (10)
- # core-async (18)
- # core-logic (1)
- # cursive (22)
- # data-science (1)
- # datalog (26)
- # datomic (35)
- # docker (1)
- # emacs (4)
- # etaoin (4)
- # fulcro (51)
- # jobs (2)
- # jobs-discuss (2)
- # joker (1)
- # leiningen (4)
- # mid-cities-meetup (1)
- # off-topic (22)
- # pathom (15)
- # re-frame (14)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (37)
- # specter (2)
- # tools-deps (43)
- # xtdb (2)
Is there a good way to get the value of a key that is the most deeply nested in a map? The map could have any level of nesting.
So if I have {:a {:a 1 :b {:c 2 :d {:a {:e 4}}}}}
I want {:e 4}
but am having trouble getting there. Thanks
you can use recursion.
(def GET-E [(s/recursive-path [] p
(s/if-path map?
(s/if-path (s/must :e) (s/continue-then-stay [s/MAP-VALS p]) [s/MAP-VALS p]) s/STOP)) (s/submap [:e])])
(s/select GET-E {:a {:a 1 :b {:c 2 :d {:a {:e 4 :l 5}}}}})
=> [{:e 4}]