Skip to content

Commit

Permalink
Make remove return a transducer when no collection is provided. (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasseglare authored Feb 11, 2025
1 parent aca7b43 commit a778b16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect

## Unreleased

- Fix [#609](https://github.com/squint-cljs/squint/issues/609): make `remove` return a transducer when no collection is provided.

## v0.8.134 (2024-02-11)

- Fix [#605](https://github.com/squint-cljs/squint/issues/605): merge command line `--paths` with `squint.edn` config properly
Expand Down
3 changes: 3 additions & 0 deletions src/squint/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ export function filterv(pred, coll) {
}

export function remove(pred, coll) {
if (arguments.length === 1) {
return filter1(complement(pred));
}
return filter(complement(pred), coll);
}

Expand Down
6 changes: 4 additions & 2 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,9 @@
(is (eq [[:a 1]] (jsv! '(vec (remove #(not= :a (first %)) {:a 1 :b 2})))))
(testing "nil"
(is (eq () (jsv! '(vec (remove odd? nil)))))
(is (eq () (jsv! '(vec (remove odd? js/undefined)))))))
(is (eq () (jsv! '(vec (remove odd? js/undefined))))))
(testing "transducer"
(is (eq [2 4 6 8] (jsv! '(into [] (remove odd?) [1 2 3 4 5 6 7 8 9]))))))

(deftest map-indexed-test
(is (eq [[0 0] [1 1] [2 2] [3 3] [4 4]]
Expand Down Expand Up @@ -1271,7 +1273,7 @@
(testing "multiple colls"
(is (eq ["a" 1 "b" 2] (jsv! '(vec (mapcat list [:a :b :c] [1 2]))))))
(testing "transducer"
(is (eq [1 1001 2 1002 3 1003] (into [] (mapcat (fn [x] [x (+ 1000 x)])) [1 2 3])))))
(is (eq [1 1001 2 1002 3 1003] (jsv! '(into [] (mapcat (fn [x] [x (+ 1000 x)])) [1 2 3]))))))

(deftest laziness-test
(is (eq ["right" "up" "left" "left" "down" "down" "right" "right" "right" "up" "up" "up" "left" "left" "left" "left" "down" "down" "down" "down"]
Expand Down

0 comments on commit a778b16

Please sign in to comment.