Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CLJS-585: ChunkedCons does not implement INext

  • Loading branch information...
commit af300b722ec5761bdc0c76fd0cc162927adb8a79 1 parent 95d92ba
@swannodette swannodette authored
Showing with 26 additions and 10 deletions.
  1. +21 −10 src/cljs/cljs/core.cljs
  2. +5 −0 test/cljs/cljs/core_test.cljs
View
31 src/cljs/cljs/core.cljs
@@ -2204,6 +2204,14 @@ reduces them without incurring seq initialization"
()
more)))
+ INext
+ (-next [coll]
+ (if (> (-count chunk) 1)
+ (ChunkedCons. (-drop-first chunk) more meta nil)
+ (let [more (-seq more)]
+ (when-not (nil? more)
+ more))))
+
IChunkedSeq
(-chunked-first [coll] chunk)
(-chunked-rest [coll]
@@ -6157,16 +6165,19 @@ reduces them without incurring seq initialization"
(defn set
"Returns a set of the distinct elements of coll."
[coll]
- (if-not (nil? coll)
- (let [^not-native in (seq coll)]
- (if (instance? IndexedSeq in)
- (set-from-indexed-seq in)
- (loop [in in
- ^not-native out (-as-transient #{})]
- (if-not (nil? in)
- (recur (-next in) (-conj! out (-first in)))
- (-persistent! out)))))
- #{}))
+ (let [^not-native in (seq coll)]
+ (cond
+ (nil? in) #{}
+
+ (instance? IndexedSeq in)
+ (set-from-indexed-seq in)
+
+ :else
+ (loop [in in
+ ^not-native out (-as-transient #{})]
+ (if-not (nil? in)
+ (recur (-next in) (-conj! out (-first in)))
+ (-persistent! out))))))
(defn hash-set
([] #{})
View
5 test/cljs/cljs/core_test.cljs
@@ -1938,5 +1938,10 @@
(assert (= #{1 2} (hash-set 1 2 2)))
(assert (= #{1 2} (apply hash-set [1 2 2])))
+ ;; CLJS-585
+ (assert (= (last (map identity (into [] (range 32)))) 31))
+ (assert (= (into #{} (range 32))
+ (set (map identity (into [] (range 32))))))
+
:ok
)
Please sign in to comment.
Something went wrong with that request. Please try again.