redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.52k stars 105 forks source link

compact on empty collection #255

Closed jiacai2050 closed 6 years ago

jiacai2050 commented 6 years ago
(let [m {:x {:y #{"apple"}}}]
  (setval [:x (compact :y) (set-elem "apple")]
          NONE
          m))
;; => {:x {:y #{}}}

I want to know what's the idiomatic way if I want this demo return {}

nathanmarz commented 6 years ago

compact needs to surround all the steps you want compacted if empty. In this case, you just need to do:

(setval [:x (compact :y (set-elem "apple"))]
          NONE
          m)