This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-19
Channels
- # announcements (24)
- # asami (25)
- # babashka (17)
- # beginners (99)
- # bitcoin (1)
- # calva (2)
- # cider (6)
- # cljs-dev (4)
- # clojure (88)
- # clojure-australia (3)
- # clojure-europe (23)
- # clojure-france (6)
- # clojure-nl (5)
- # clojure-uk (31)
- # clojured (1)
- # clojurescript (6)
- # clojureverse-ops (1)
- # datomic (28)
- # depstar (18)
- # emacs (11)
- # events (1)
- # fulcro (21)
- # graalvm (4)
- # graphql (7)
- # heroku (1)
- # jackdaw (18)
- # joker (3)
- # kaocha (1)
- # lsp (1)
- # malli (13)
- # meander (4)
- # off-topic (12)
- # pathom (14)
- # pedestal (2)
- # podcasts-discuss (1)
- # re-frame (37)
- # reagent (17)
- # reitit (9)
- # shadow-cljs (44)
- # xtdb (17)
Hey, I’m trying to get started with meander.
(let [data {:a {:b "hi"}}]
(let [?x (m/match data
{:a {:b ?x}}
?x)]
(m/subst {:a {:b ?x}})))
This works fine but I don’t want to repeat the shape that I’m matching against.
(let [data {:a {:b "hi"}}]
(let [shape '{:a {:b ?x}}
?x (m/match data
~shape
?x)]
(m/subst ~shape)))
How do I pull the shape out?More context for what I’m trying to accomplish: I want to get data out, apply a function, and then put the data back. I started with lenses but that got messy fast.
(lens/over
(lens/in [:a :b])
reverse
{:a {:b "hi"}}) ;; {:a {:b ("i" "h")}}
So for meander, if you find yourself quoting things to try and make things more concise, you are probably not going to have a great time. We do have an interpreter for more dynamic things. But, in general, we value clarity over concision. So, you might repeat yourself a couple times, but we think it pays off. Here are two examples that might help with the sorts of things you are looking to do.
(m/match {:a {:b "hi"}}
{:a {:b ?x}}
{:a {:b (string/reverse ?x)}})
(m/rewrite {:a {:b ["things" "here"]}}
{:a {:b [!xs ...]}}
{:a {:b [(m/app string/reverse !xs) ...]}})