Created
December 20, 2017 21:30
-
-
Save nathanmarz/74d4083482637b52708148c7b8c0ed63 to your computer and use it in GitHub Desktop.
Remove empty subvalues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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