diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs index eda9c29b36..941c187f58 100644 --- a/src/cljs/cljs/core.cljs +++ b/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 ([] #{}) diff --git a/test/cljs/cljs/core_test.cljs b/test/cljs/cljs/core_test.cljs index ad6860052a..e509b6e8ac 100644 --- a/test/cljs/cljs/core_test.cljs +++ b/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 )