With match you can just use assoc or update.
(m/match {:name "jimmy"
:stuff 1}
{:name ?name
:as ?my-map}
(assoc ?my-map :extra-name ?name))
But if you want to do something a little more meandery, you could use rewrite.
(m/rewrite {:name "jimmy"
:other-name "Stuff"
:stuff 1}
{:name ?name
:other-name _
& ?rest}
{:name (m/app str "hello " ?name)
:other-name "thing"
& ?rest})
Thanks! I'll try those out
It seems like meander is great for querying a data structure or re-writing it in a different shape, but that if I want a straightforward assoc-in
or update-in
then it's just as clear and concise to use assoc-in
and upate-in
directly. Is that fair? I'm still getting the hang of where it makes sense to use meander.
It all depends on the context and what you like. 🙂
assoc-in
and update-in
are nice when their mix of semantics, convenience, etc. are more practical. rewrite
is specifically designed for shape to shape transformation, not “in-place” transformation. That being said, you can still do nested transformations with rewrite
by using the cata
operator, this is my personal tendency.
I’d love to hear your thoughts, good and bad, on how it works with your re-frame app.
I’ve wanted to mess around with something like that. 👍
[meander/epsilon "0.0.421"]
is out which addresses the cases where bad Clojure code being generated would trigger a clojure.lang.Compiler$CompilerException
due to symbols being unresolveable.
@nlessa ☝️ that should patch your problem, I even used it as https://github.com/noprompt/meander/commit/3335fc72eae0e3c6d30c9ac6a265b3ccf790f3ce#diff-e7544f9bb8134fa6cdaaa573a3b2a601R2426.
I’m sorry it took me so long to patch it. I was on vacation last week, busy before that, and couldn’t take a serious look until today.
Thank you, Joel! No problem at all. And thanks a lot for your time and effort to create meander. It really opened new paths to develop some stuff I have been working with.
@noprompt I'll let you know how it goes with re-frame. I thought meander match might offer a clear way to write queries that involve joins, which seem to often come up when using the "https://purelyfunctional.tv/guide/database-structure-in-re-frame/#Indexed-Entities-Pattern" for db structure described by Eric Normand. So far so good :-)