meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
schmee 2020-10-16T14:53:53.242800Z

I finally have a real use-case for Meander! 🎉

schmee 2020-10-16T14:54:10.243200Z

I’ve already managed to do what I want, which is great, but is there any way to remove the duplication in this rewrite?

schmee 2020-10-16T14:54:12.243500Z

(m*/rewrite
    [:and [!as ...]] [:and . !as ...]
    [:or [!as ...]] [:or . !as ...]))

schmee 2020-10-16T14:55:01.244100Z

basically, :and and :or are both operators, so the pattern should be, “if the first element is an operator…”

jimmy 2020-10-16T14:57:27.244400Z

Do you have a defined set of operators you want to match on?

schmee 2020-10-16T14:58:12.244600Z

yes, the set of operators is fixed!

jimmy 2020-10-16T15:00:44.244800Z

On my phone, but you should be able to do (m/pred #{:and :or} ?op)

schmee 2020-10-16T15:09:38.245Z

worked like a charm, thanks! 🚀

schmee 2020-10-16T15:11:40.245200Z

follow-up: is there any way to bind this pattern to a name so I can re-use it in all the rules without re-typing it?

schmee 2020-10-16T15:12:07.245400Z

I tried m/let but at least on my first attempt it didn’t do the trick

jimmy 2020-10-16T15:16:31.245600Z

You can use with https://cljdoc.org/d/meander/epsilon/0.0.512/doc/operator-overview#with

🎉 1