Skip to content

Commit 6062744

Browse files
slipsetswannodette
authored andcommitted
CLJS-2911 Avoid infinite loop on infinite partitions
1 parent 71f5771 commit 6062744

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9721,7 +9721,7 @@ reduces them without incurring seq initialization"
97219721
(let [fst (first s)
97229722
fv (f fst)
97239723
run (cons fst (take-while #(= fv (f %)) (next s)))]
9724-
(cons run (partition-by f (seq (drop (count run) s)))))))))
9724+
(cons run (partition-by f (lazy-seq (drop (count run) s)))))))))
97259725

97269726
(defn frequencies
97279727
"Returns a map from distinct items in coll to the number of times

src/test/cljs/cljs/seqs_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,7 @@
216216
(deftest test-cljs-2482
217217
(testing "seq on defrecord returns map entries"
218218
(is (every? map-entry? (seq (->Foo 1 2))))))
219+
220+
(deftest test-cljs-2911
221+
(testing "partition-by works correclty with infinite seqs"
222+
(is (= (first (second (partition-by zero? (range)))) 1))))

0 commit comments

Comments
 (0)