Skip to content
Browse files

CLJS-635: ensure that rseq of empty collections always returns nil

  • Loading branch information...
1 parent 2fd9786 commit 3da27a0aff346ac1528ebf79aebf2329e96d34c9 @cemerick cemerick committed with swannodette
Showing with 12 additions and 9 deletions.
  1. +6 −8 src/cljs/cljs/core.cljs
  2. +6 −1 test/cljs/cljs/core_test.cljs
View
14 src/cljs/cljs/core.cljs
@@ -708,8 +708,7 @@ reduces them without incurring seq initialization"
(-rseq [coll]
(let [c (-count coll)]
(if (pos? c)
- (RSeq. coll (dec c) nil)
- ()))))
+ (RSeq. coll (dec c) nil)))))
(defn prim-seq
([prim]
@@ -749,8 +748,7 @@ reduces them without incurring seq initialization"
(-nth ci i))
(-rest [coll]
(if (pos? i)
- (RSeq. ci (dec i) nil)
- ()))
+ (RSeq. ci (dec i) nil)))
ICounted
(-count [coll] (inc i))
@@ -1933,7 +1931,7 @@ reduces them without incurring seq initialization"
(defn ^boolean reversible? [coll]
(satisfies? IReversible coll))
-(defn rseq [coll]
+(defn ^seq rseq [coll]
(-rseq coll))
(defn reverse
@@ -3315,8 +3313,7 @@ reduces them without incurring seq initialization"
IReversible
(-rseq [coll]
(if (pos? cnt)
- (RSeq. coll (dec cnt) nil)
- ())))
+ (RSeq. coll (dec cnt) nil))))
(set! cljs.core.PersistentVector.EMPTY_NODE (VectorNode. nil (make-array 32)))
@@ -6147,7 +6144,8 @@ reduces them without incurring seq initialization"
IReversible
(-rseq [coll]
- (map key (rseq tree-map)))
+ (if (pos? (count tree-map))
+ (map key (rseq tree-map))))
ICounted
(-count [coll] (count tree-map))
View
7 test/cljs/cljs/core_test.cljs
@@ -1025,7 +1025,10 @@
(let [pv (vec (range 97))]
(assert (= (nth pv 96) 96))
(assert (= (nth pv 97 nil) nil))
- (assert (= (pv 96) 96)))
+ (assert (= (pv 96) 96))
+ (assert (nil? (rseq [])))
+ (assert (= (reverse pv) (rseq pv))))
+
(let [pv (vec (range 33))]
(assert (= pv
@@ -1328,6 +1331,7 @@
(assert (identical? compare (.-comp m1)))
(assert (zero? (count m1)))
(assert (zero? (count m2)))
+ (assert (nil? (rseq m1)))
(let [m1 (assoc m1 :foo 1 :bar 2 :quux 3)
m2 (assoc m2 :foo 1 :bar 2 :quux 3)]
(assert (= (count m1) 3))
@@ -1374,6 +1378,7 @@
(assert (identical? compare (-comparator s1)))
(assert (zero? (count s1)))
(assert (zero? (count s2)))
+ (assert (nil? (rseq s1)))
(let [s1 (conj s1 1 2 3)
s2 (conj s2 1 2 3)
s3 (conj s3 1 2 3 7 8 9)

0 comments on commit 3da27a0

Please sign in to comment.
Something went wrong with that request. Please try again.