Skip to content

Commit af300b7

Browse files
committed
CLJS-585: ChunkedCons does not implement INext
1 parent 95d92ba commit af300b7

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/cljs/cljs/core.cljs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,14 @@ reduces them without incurring seq initialization"
22042204
()
22052205
more)))
22062206

2207+
INext
2208+
(-next [coll]
2209+
(if (> (-count chunk) 1)
2210+
(ChunkedCons. (-drop-first chunk) more meta nil)
2211+
(let [more (-seq more)]
2212+
(when-not (nil? more)
2213+
more))))
2214+
22072215
IChunkedSeq
22082216
(-chunked-first [coll] chunk)
22092217
(-chunked-rest [coll]
@@ -6157,16 +6165,19 @@ reduces them without incurring seq initialization"
61576165
(defn set
61586166
"Returns a set of the distinct elements of coll."
61596167
[coll]
6160-
(if-not (nil? coll)
6161-
(let [^not-native in (seq coll)]
6162-
(if (instance? IndexedSeq in)
6163-
(set-from-indexed-seq in)
6164-
(loop [in in
6165-
^not-native out (-as-transient #{})]
6166-
(if-not (nil? in)
6167-
(recur (-next in) (-conj! out (-first in)))
6168-
(-persistent! out)))))
6169-
#{}))
6168+
(let [^not-native in (seq coll)]
6169+
(cond
6170+
(nil? in) #{}
6171+
6172+
(instance? IndexedSeq in)
6173+
(set-from-indexed-seq in)
6174+
6175+
:else
6176+
(loop [in in
6177+
^not-native out (-as-transient #{})]
6178+
(if-not (nil? in)
6179+
(recur (-next in) (-conj! out (-first in)))
6180+
(-persistent! out))))))
61706181

61716182
(defn hash-set
61726183
([] #{})

test/cljs/cljs/core_test.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,5 +1938,10 @@
19381938
(assert (= #{1 2} (hash-set 1 2 2)))
19391939
(assert (= #{1 2} (apply hash-set [1 2 2])))
19401940

1941+
;; CLJS-585
1942+
(assert (= (last (map identity (into [] (range 32)))) 31))
1943+
(assert (= (into #{} (range 32))
1944+
(set (map identity (into [] (range 32))))))
1945+
19411946
:ok
19421947
)

0 commit comments

Comments
 (0)