disj returns a set with one or more specified elements removed. It accepts a set followed by zero or more removal values and supports both ordinary and sorted sets. section 13.4 section 13.0
Its contract includes these practical cases:
- With only the set argument, disj returns that argument unchanged, including nil. section 13.4
- With additional arguments, the input must implement IPersistentSet; otherwise disj can throw ClassCastException. section 13.4
- Removal values may have any type, and missing values simply leave the set unchanged. section 13.4
Removing several elements
(disj #{1 4 6 8} 4 8) ;; #{1 6} (disj (sorted-set-by > 1 4 6) 4) ;; #{6 1}
Detecting unwanted values
Convert the values to a set, remove every allowed value, and test whether anything remains: (defn valid? [allowed values] (empty? (apply disj (set values) allowed))) (valid? [:a :b :c] [:c :c 1 :a]) ;; false (valid? [:a :b :c] [:c :c :a]) ;; true
