This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-19
Channels
- # announcements (3)
- # babashka (42)
- # beginners (84)
- # calva (3)
- # cider (13)
- # clj-kondo (9)
- # cljs-dev (6)
- # cljsrn (32)
- # clojure (47)
- # clojure-argentina (4)
- # clojure-france (2)
- # clojure-spec (17)
- # clojure-uk (15)
- # clojuredesign-podcast (4)
- # clojurescript (41)
- # conjure (53)
- # cursive (16)
- # data-science (5)
- # duct (1)
- # emacs (11)
- # events (1)
- # exercism (3)
- # fulcro (48)
- # graalvm (20)
- # graphql (1)
- # joker (3)
- # kaocha (2)
- # malli (2)
- # meander (6)
- # pathom (3)
- # planck (18)
- # rdf (3)
- # re-frame (14)
- # ring-swagger (1)
- # shadow-cljs (15)
- # specter (1)
Subtle variant of that:
(def path-finder
"Finds the first entry matching `pred` in a deeply nested structure of maps
and vectors, and collects the path on the way there."
(sr/recursive-path
[term-pred] p
(sr/cond-path
(sr/pred term-pred) sr/STAY
map? [INDEXED p]
coll? [INDEXED-SEQ p])))
(basically the same thing but with a predicate). This works fine (as expected when selecting):
(sr/select
(path-finder string?)
{:a ["x"] :b {:c :d}})
;; => [[:a 0 "x"]]
But when transforming I get this unexpected behavior:
(= (sr/transform
[(path-finder string?)]
(fn [& path-and-val] (-> path-and-val last str/upper-case))
{:a ["x"] :b {:c :d}})
(sr/transform
[NESTED-PATHS string?]
(fn [& path-and-val] (-> path-and-val last str/upper-case))
{:a ["x"] :b {:c :d}})
{:a '([0 "X"]), :b {:c :d}})
Why is that zero there all of a sudden and how do I fix that?