thanks Timothy! Nice trick!
(m/match
{:a 1
:b 2}
{:a !v
& (m/or {:b !v}
{})}
!v)
^^ is this the “right” way to do optional keys?Yes everything is optional by default. my answer was assuming you just didn't want the nil to be in your memory variable. Technically it isn't just guard or pred. If you put a vector pattern for example that means you are asserting that there is some non nil vector there.
Any reason not to do just (m/or nil !v)?
I’m not following :thinking_face:
I’m matching something like {:methods [1 2 3] :resources {:methods [4 5 6]}}
where a resource has methods and optionally a sub resource with methods etc and am using this:
(def extract-resource-methods
(s/rewrite
(m/with [%resource {:methods {& (m/seqable [_ !methods] ...)}
& (m/or {:resources {& (m/seqable [_ %resource] ...)}}
{})}]
[?baseUrl %resource])
;;=>
[[?baseUrl !methods] ...]))
to represent that :resources
may or may not be present… it just seems a little wierd like I’m over complicating it.This is a bug not 100% sure the correct fix for this. But should have a fix tomorrow or monday.
I guess more importantly I don’t see a way to do many optional keys
oh I think I see…
(m/match
{:a 1}
{:a ?a
:b ?b}
[?a ?b])
=> [1 nil]
^^ I didn’t realize that meander matches patterns even if not all keys are present hmmm. :thinking_face: I guess then everything is optional unless I do a pred or guard. 🙂[meander/epsilon "0.0.401"]
• Fixes some issues with or
pattern compilation
• Fixes uses of transients in substitution codeThe or stuff didn't actually land in this release. But we will cut a new one soon with the or fix.