Fork me on GitHub

  {:a 1
   :b 2}
  {:a !v
   & (m/or {:b !v}
^^ is this the “right” way to do optional keys?


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
    (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.


I guess more importantly I don’t see a way to do many optional keys


oh I think I see…

  {: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. 🙂


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.


[meander/epsilon "0.0.401"]
• Fixes some issues with or pattern compilation • Fixes uses of transients in substitution code


The or stuff didn't actually land in this release. But we will cut a new one soon with the or fix.

👍 8