meander

David G 2022-11-04T19:55:57.107169Z

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?

jgdavey 2022-11-04T19:58:26.051339Z

Perhaps you want m/rewrite? `

David G 2022-11-04T19:59:03.197799Z

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

jgdavey 2022-11-04T19:59:11.753449Z

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

jgdavey 2022-11-04T20:01:11.530539Z

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

David G 2022-11-04T20:05:05.446479Z

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