Skip to content

Commit 628d957

Browse files
mfikesswannodette
authored andcommitted
CLJS-1546: cljs.core/run! does not always return nil
The cljs.core/run! function only returns nil if the proc function passed to it returns nil, but the docstring for run! indicates that it returns nil. Fixes this issue by explicitly returning nil. This also makes the ClojureScript implementation of run! match that in Clojure 1.8. Adds unit tests for run!, copying tests from Clojure that exhibit the bug, while also adding a test for the primary functionality.
1 parent 7dfebbb commit 628d957

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9293,8 +9293,8 @@ reduces them without incurring seq initialization"
92939293
"Runs the supplied procedure (via reduce), for purposes of side
92949294
effects, on successive items in the collection. Returns nil"
92959295
[proc coll]
9296-
(reduce #(proc %2) nil coll))
9297-
9296+
(reduce #(proc %2) nil coll)
9297+
nil)
92989298

92999299
(defprotocol IEncodeJS
93009300
(-clj->js [x] "Recursively transforms clj values to JavaScript")

src/test/cljs/cljs/core_test.cljs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,16 @@
907907
(is (contains? "f" 0))
908908
(is (not (contains? "f" 55)))))
909909

910+
(deftest test-run!
911+
(testing "Testing run!"
912+
(let [a (atom 0)]
913+
(run! (fn [n]
914+
(swap! a + n))
915+
(range 5))
916+
(is (= 10 @a)))
917+
(is (nil? (run! identity [1])))
918+
(is (nil? (run! reduced (range))))))
919+
910920
(deftest test-distinct
911921
(testing "Testing distinct? & distinct"
912922
(is (distinct? 1 2 3))

0 commit comments

Comments
 (0)