Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support predicate checks within a collection with =? #23

Open
tsmacdonald opened this issue Apr 8, 2024 · 1 comment
Open

Support predicate checks within a collection with =? #23

tsmacdonald opened this issue Apr 8, 2024 · 1 comment

Comments

@tsmacdonald
Copy link
Contributor

(deftest foo-test
  (is (=? even? 4)) ; passes
  (is (=? {:foo even?} {:foo 42})) ; passes
  (is (=? #{even?} #{2 4 6 8})))  ; fails: expected #{even?}, actual #{2 4 6 8}

If there's a collection that includes exactly one item which is a predicate function, I think =? should check that the actual value is of the given collection type and all of its elements pass the predicate.

Motivating example in the wild from Metabase

@crisptrutski
Copy link
Contributor

crisptrutski commented Apr 8, 2024

The support I wanted was not for broadcasting a single predicate, but to support matching between sets of equal size. In general this is a bipartite mapping problem that can't be solved greedily, but a greedy approach is probably good enough for 99.9% of cases.

Another tricky things is disambiguating sets as collections or functions.

What I want:

(is (=? #{#{1} even? zero?} #{0 2 1})) ;; true
(is (=? #{#{1} even? zero?} #{2 1})) ;; false
(is (=? #{#{1} even? zero?} #{2 1 4 0})) ;; false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants