-
Notifications
You must be signed in to change notification settings - Fork 23
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
match? mismatches predicates when applied to keys in maps #132
Comments
/cc @philomates @nubank/eng-prod-test |
This will probably slow matching down quite a bit because matching keys in a map instead of normal clojure equality is complexity-wise like matching an unordered list. Matching an unordered list is slow because you can have "overlapping" predicates ( I sorta think we shouldn't implement this, given the runtime cost, additional implementation complexity, and as far as I know, nobody has felt its absence yet. Or we could implement it as a special matcher, such that key matching only happens when the |
Implementation-wise though, I had the idea that matching something like (match?
{keyword? odd? :x pos?}
{:a 1 :x -1 :whatever "foo"} could be recast as (match?
(embeds [[keyword? odd?] [:x pos?]])
[[:a 1] [:x -1] [:whatever "foo"]]) with some adaptations on the resulting mismatch message |
@philomates if we don't add support for predicates, we should at least document that fact. Maybe even an error or warning? WDYT? |
since (match? {symbol? 2
symbol? 1}
{'x 1 'y 2}) fails with
we could do something similar to what we did with (match? (m/embeds 'map
[[symbol? 2]
[symbol? 1]])
{'x 1 'y 2}) I'm not sure if adding this functionality is worth the additional complexity in both the library's capabilities, speed, and its implementation. |
The text was updated successfully, but these errors were encountered: