Skip to content

Commit 7bf6846

Browse files
kotarakstuarthalloway
authored andcommitted
Make disj nil-aware
Refers #360 Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
1 parent fb52b69 commit 7bf6846

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/clj/clojure/core.clj

+7-5
Original file line numberDiff line numberDiff line change
@@ -1168,12 +1168,14 @@
11681168
{:added "1.0"}
11691169
([set] set)
11701170
([^clojure.lang.IPersistentSet set key]
1171-
(. set (disjoin key)))
1171+
(when set
1172+
(. set (disjoin key))))
11721173
([set key & ks]
1173-
(let [ret (disj set key)]
1174-
(if ks
1175-
(recur ret (first ks) (next ks))
1176-
ret))))
1174+
(when set
1175+
(let [ret (disj set key)]
1176+
(if ks
1177+
(recur ret (first ks) (next ks))
1178+
ret)))))
11771179

11781180
(defn find
11791181
"Returns the map entry for key, or nil if key not present."

test/clojure/test_clojure/data_structures.clj

+4
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@
728728

729729
; identity
730730
(are [x] (= (disj x) x)
731+
nil
731732
#{}
732733
#{1 2 3}
733734
; different data types
@@ -753,6 +754,9 @@
753754
(sorted-set 1 2) )
754755

755756
(are [x y] (= x y)
757+
(disj nil :a) nil
758+
(disj nil :a :b) nil
759+
756760
(disj #{} :a) #{}
757761
(disj #{} :a :b) #{}
758762

0 commit comments

Comments
 (0)