I have a Clojure map that may contain values that are nil and I'm trying to write a function to remove them, without much success (I'm new to this).
E.g.:
(def record {:a 1 :b 2 :c nil})
(merge (for [[k v] record :when (not (nil? v))] {k v}))
This results in a sequence of maps, which isn't what I expected from merge:
({:a 1} {:b 2})
I would like to have:
{:a 1, :b 2}
Jürgen Hötzel solution refined to fix the nil/false issue
A bit shorter version of @thnetos solution
Here's one that works on maps and vectors:
Here is one that works on nested maps: