Skip to content

Commit ca19a52

Browse files
committed
CLJS-1209: Reduce produces additional final nil when used w/ eduction
Eduction IReduce implementations must wrap `f` in `completing`
1 parent dc7e97a commit ca19a52

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8940,8 +8940,8 @@ reduces them without incurring seq initialization"
89408940
(-seq [_] (seq (sequence xform coll)))
89418941

89428942
IReduce
8943-
(-reduce [_ f] (transduce xform f coll))
8944-
(-reduce [_ f init] (transduce xform f init coll))
8943+
(-reduce [_ f] (transduce xform (completing f) coll))
8944+
(-reduce [_ f init] (transduce xform (completing f) init coll))
89458945

89468946
IPrintWithWriter
89478947
(-pr-writer [coll writer opts]

src/test/cljs/cljs/core_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,14 @@
28142814
(deftest test-cljs-1225
28152815
(is (= (incme) 2)))
28162816

2817+
(defn my-conj
2818+
[acc x]
2819+
(conj acc x))
2820+
2821+
(deftest test-cljs-1209
2822+
(is (= (reduce my-conj [] (eduction (map identity) [1 2 3]))
2823+
[1 2 3])))
2824+
28172825
(comment
28182826
;; ObjMap
28192827
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)