This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-13
Channels
- # aleph (3)
- # aws (1)
- # beginners (97)
- # boot (41)
- # cider (7)
- # clara (105)
- # cljs-dev (4)
- # cljsrn (66)
- # clojure (185)
- # clojure-argentina (2)
- # clojure-colombia (15)
- # clojure-czech (1)
- # clojure-dusseldorf (8)
- # clojure-greece (2)
- # clojure-italy (5)
- # clojure-russia (33)
- # clojure-spec (14)
- # clojure-uk (9)
- # clojurescript (75)
- # cursive (6)
- # data-science (1)
- # datomic (12)
- # emacs (2)
- # fulcro (71)
- # funcool (1)
- # jobs (6)
- # jobs-discuss (62)
- # juxt (21)
- # lein-figwheel (1)
- # luminus (9)
- # lumo (41)
- # off-topic (39)
- # om (12)
- # onyx (1)
- # portkey (2)
- # protorepl (4)
- # re-frame (14)
- # reagent (50)
- # ring (3)
- # shadow-cljs (6)
- # spacemacs (38)
- # specter (8)
- # test-check (14)
- # testing (52)
- # unrepl (2)
I’m stuck writing a selector: I’d like to recursively walk down nested maps, and, if I get a choice, deepest first. So, for:
{"a" {"b" {"c" 1}}}
I’d get {"c" 1}
, {"b" {"c" 1}}
, {"a" {"b" {"c" 1}}}
. I’ve been messing around with recursive-path but haven’t gotten far.writing the nested traversal that just grabs the values at the leaves is easy:
(sr/recursive-path
[] p
(sr/cond-path
map? (sr/stay-then-continue [p sr/MAP-VALS])
sr/STAY sr/STAY))
This is almost what I want:
(def tree-vals
(sr/recursive-path
[] p
(sr/if-path map?
[sr/VAL sr/MAP-VALS p]
sr/STAY)))
is almost what I want: it just returns the 1
too(sr/NONE still selects nil; and I’m not sure how to say “ok you’re done now” — I don’t think it’s STOP, because that just stops navigation entirely, right?)
Got it:
(def tree-vals
(sr/recursive-path
[] p
(sr/if-path map? (sr/continue-then-stay [sr/MAP-VALS p]))))
@lvh you can omit the []
in continue-then-stay
no performance difference, just a little nicer