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
ahh
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}