Skip to content

Instantly share code, notes, and snippets.

@nathanmarz
Created December 20, 2017 21:30
Show Gist options
  • Save nathanmarz/74d4083482637b52708148c7b8c0ed63 to your computer and use it in GitHub Desktop.
Save nathanmarz/74d4083482637b52708148c7b8c0ed63 to your computer and use it in GitHub Desktop.
Remove empty subvalues
(let [ensure* (stay-then-continue (if-path empty? (terminal-val NONE)))]
(defdynamicnav ensure [& path]
(interleave (repeat (count path) ensure*) path)
))
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1}}})
;; => {}
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1} :d 2}})
;; => {:a {:d 2}}
(setval [ALL (ensure :a ALL :b)]
NONE
[{:a [{:b 3}]}
{:a [{:b 2 :c 1}]}])
;; => [{:a [{:c 1}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment