Skip to content

Commit

Permalink
CLJS-585: ChunkedCons does not implement INext
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Sep 5, 2013
1 parent 95d92ba commit af300b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/cljs/cljs/core.cljs
Expand Up @@ -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]
Expand Down Expand Up @@ -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
([] #{})
Expand Down
5 changes: 5 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -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
)

0 comments on commit af300b7

Please sign in to comment.