meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
nlessa 2020-03-01T01:08:49.091400Z

thanks Timothy! Nice trick!

timothypratley 2020-03-01T02:15:38.092100Z

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

jimmy 2020-03-01T14:39:57.094400Z

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.

jimmy 2020-03-01T02:19:48.092200Z

Any reason not to do just (m/or nil !v)?

timothypratley 2020-03-01T03:25:23.092400Z

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.

jimmy 2020-03-01T05:15:27.092600Z

This is a bug not 100% sure the correct fix for this. But should have a fix tomorrow or monday.

timothypratley 2020-03-01T06:33:20.092800Z

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

timothypratley 2020-03-01T07:11:19.094200Z

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

noprompt 2020-03-01T21:10:12.096400Z

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

noprompt 2020-03-01T21:10:58.097Z

Thanks @jimmy, @aisamu, @qythium

🙏 1
jimmy 2020-03-01T22:35:52.098Z

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

👍 2