Skip to content

Commit

Permalink
Fix re-usage of reductions return value
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 7, 2023
1 parent 713e850 commit 5837bad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/squint/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,13 @@ function _reductions3(f, init, coll) {
export function reductions(f, arg1, arg2) {
f = toFn(f);
if (arg2 === undefined) {
return _reductions2(f, arg1);
return lazy(function* () {
yield* _reductions2(f, arg1);
});
}
return _reductions3(f, arg1, arg2);
return lazy(function* () {
yield* _reductions3(f, arg1, arg2);
});
}

var tolr = false;
Expand Down
8 changes: 7 additions & 1 deletion test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,13 @@
(is (= 100 (jsv! '(do (def a (atom []))
(defn spy [x] (swap! a conj x) x)
(vec (reductions + (map spy (range 100))))
(count @a)))))))
(count @a)))))
(is (eq (do
(let [ xs (reductions + (range 3))]
[(count xs) (count xs)]))
(jsv! '(do
(let [ xs (reductions + (range 3))]
[(count xs) (count xs)])))))))

(deftest seq-test
(is (= "abc" (jsv! '(seq "abc"))))
Expand Down

0 comments on commit 5837bad

Please sign in to comment.