specter 2025-01-27

Is there a way to use compact with transform, or otherwise cause a key in a map to be removed if the result of transforming a map value is an empty collection?

(s/transform [:b] #(disj % 1 2 3) {:a #{5 6} :b #{2 3}})
{:a #{6 5}, :b #{}}

(s/transform <something?> #(disj % 1 2 3) {:a #{5 6} :b #{2 3}})
{:a #{6 5}}

you just need compact wrapped around the navigator on the data structure

since your transform fn is handling everything internally, you can do it like this: (transform [:b (compact STAY)] #(disj % 1 2 3) {:a #{5 6} :b #{2 3}})

👍 1