Permalink
Browse files

Make disj nil-aware

Refers #360

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent fb52b69 commit 7bf68461de66ef2d204487e345b2af18418ea581 @kotarak kotarak committed with stuarthalloway May 27, 2010
Showing with 11 additions and 5 deletions.
  1. +7 −5 src/clj/clojure/core.clj
  2. +4 −0 test/clojure/test_clojure/data_structures.clj
View
12 src/clj/clojure/core.clj
@@ -1168,12 +1168,14 @@
{:added "1.0"}
([set] set)
([^clojure.lang.IPersistentSet set key]
- (. set (disjoin key)))
+ (when set
+ (. set (disjoin key))))
([set key & ks]
- (let [ret (disj set key)]
- (if ks
- (recur ret (first ks) (next ks))
- ret))))
+ (when set
+ (let [ret (disj set key)]
+ (if ks
+ (recur ret (first ks) (next ks))
+ ret)))))
(defn find
"Returns the map entry for key, or nil if key not present."
View
4 test/clojure/test_clojure/data_structures.clj
@@ -728,6 +728,7 @@
; identity
(are [x] (= (disj x) x)
+ nil
#{}
#{1 2 3}
; different data types
@@ -753,6 +754,9 @@
(sorted-set 1 2) )
(are [x y] (= x y)
+ (disj nil :a) nil
+ (disj nil :a :b) nil
+
(disj #{} :a) #{}
(disj #{} :a :b) #{}

0 comments on commit 7bf6846

Please sign in to comment.