specter

Andrew Wilcox 2025-01-27T02:18:14.569749Z

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}}

nathanmarz 2025-01-27T03:54:28.370309Z

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

nathanmarz 2025-01-27T03:54:53.026999Z

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