Fork me on GitHub
#meander
<
2022-06-27
>
wilkerlucio14:06:40

hello, how can I make a pattern that says a key must not be in the map?

Ben Sless14:06:18

Maybe by writing a pattern that fails (bottom) if it succeed in matching a key in a map? (and {k (some v)} fail)

wilkerlucio14:06:09

I found that just using {:key nil} seems to work fine

Ben Sless14:06:27

What if the key exists with a nil value? Is it possible?

wilkerlucio14:06:59

I think in this case will match the same, which is fine for my use case but I can see some other case might wanna know the difference

noprompt19:06:52

There is currently not a (clean) way to distinguish between a missing key and a key with a nil value. 😐

wilkerlucio19:06:36

I think something in the direction of what match combinators do would be interesting to have in meander, for the case we are discussing they have the absent matcher (https://github.com/nubank/matcher-combinators#negative-matchers)

wilkerlucio19:06:10

it is possible to make a custom syntax on meander for that?

noprompt19:06:10

For interpreted Meander, sure, but for compiled, it’s possible but too much work for the time I am currently making for the project (which has only been on the zeta branch). The issue boils down to compiled meander resolving key values with get. We could switch to find for specific keys but, again, it’s a lot of work. A workaround be papered over with defsyntax

{& (m/scan [:foo ?x])}

noprompt19:06:50

Use {} to ensure you get a map, then m/scan the keys. But that is really kinda ugly.

noprompt19:06:01

{:foo ?foo & (not ?x) :as ?x}
Might work too.

noprompt19:06:38

Right because if ?x is {} and & ?x succeeds then you know :foo isn’t a key.