This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-30
Channels
- # aws (4)
- # beginners (143)
- # boot (37)
- # cider (31)
- # cljs-dev (53)
- # clojure (303)
- # clojure-conj (5)
- # clojure-dev (106)
- # clojure-dusseldorf (2)
- # clojure-greece (3)
- # clojure-italy (23)
- # clojure-spec (83)
- # clojure-uk (7)
- # clojurescript (328)
- # core-async (25)
- # cursive (2)
- # datascript (2)
- # datomic (3)
- # emacs (10)
- # hoplon (1)
- # jobs (2)
- # lein-figwheel (1)
- # leiningen (13)
- # luminus (6)
- # off-topic (38)
- # onyx (2)
- # parinfer (13)
- # pedestal (2)
- # portkey (5)
- # re-frame (11)
- # reagent (2)
- # shadow-cljs (61)
- # specter (6)
- # unrepl (60)
- # vim (4)
trying to recursively remove map entries with nil values. here’s a start on the path:
(def nil-map-entries
(spr/recursive-path [] p
(spr/cond-path
#(and (instance? MapEntry %)
(nil? (val %)))
spr/STAY
#(coll? %)
[spr/ALL p])))
although i can select them with this, transforming doesn’t seem to match on them: (spr/select [nil-map-entries] {:foo nil :bar :bam})
=> [[:foo nil]]
(spr/transform [nil-map-entries] (constantly spr/NONE) {:foo nil :bar :bam})
=> {:foo nil, :bar :bam}
never experienced this kind of incongruity@spieden specter navigates to vector for map entries on transform, not MapEntry
object
I suggest handling maps separately from other collections in your path, which will make navigation more explicit and remove the need to check the type
ok thanks! @nathanmarz
here’s what i wound up with, for posterity:
(def nil-map-entries
(spr/recursive-path [] p
(spr/cond-path
map?
[spr/ALL (spr/if-path #(nil? (second %))
spr/STAY
p)]
#(coll? %)
[spr/ALL p])))
(spr/transform [nil-map-entries] (constantly spr/NONE) {:foo {:baz nil} :bar :bam})
=> {:foo {}, :bar :bam}