Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a key from a clojure tree using specter?

I have been coming up to speed using the Clojure Specter library (https://github.com/nathanmarz/specter). What I am having an issue with is removing a key using transform or setval. I can set it to nil, but how do I remove a key?

like image 765
Chaos Rules Avatar asked Nov 07 '15 21:11

Chaos Rules


2 Answers

(setval :a NONE {:a 10 :b 20})
=> {:b 20}
like image 147
alex.dorokhov Avatar answered Nov 10 '22 14:11

alex.dorokhov


This seems to work:

(transform [ALL] #(when (not= (key %) :a) %) {:a 1 :b 2})
=> {:b 2}
like image 35
leeor Avatar answered Nov 10 '22 14:11

leeor