Fork me on GitHub
#meander
<
2022-11-04
>
David G19:11:57

I’m trying to mimic Clojure’s update but I’m struggling to understand how to do sort of in-place updates to maps using match:

(m/match {:a 1 :b 3}
  {:a ?a & _}
  {:a (inc ?a)
   ????})
In this small example I’m trying to perform inc only on :a (and perhaps do that for several other keywords, but this is the basic form of what I’m trying to do). How do you stitch back the “rest” of the map?

jgdavey19:11:26

Perhaps you want m/rewrite? `

David G19:11:03

I thought rewrite outputs a match pattern given an input which you can match against

jgdavey19:11:11

(m/rewrite {:a 1 :b 3}
  {:a ?a & ?m}
  {:a (m/app inc ?a) & ?m})

jgdavey20:11:11

rewrite’s “action” branch is pattern-like, as opposed to match/search/find which are more like literal clojure

David G20:11:05

“action” is the second parameter in this case, right?