meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
nivekuil 2020-10-10T07:41:25.230200Z

ok, here's another one that I think is doable, but can't figure out: find an elt in vec that is a map with the key :a, and wrap it with a list with something arbitrary added like: [1 2 {:a 1} {:d 4}] => [1 2 ({:a 1} 99) {:d 4}]

Lucy Wang 2020-10-10T07:45:12.231200Z

use the subtree search operator m/$

(m/match [1 2 {:a 1} {:d 4}]
  (m/$ ?context {:a ?a})
  (?context (list {:a ?a} 99)))
;; => [1 2 ({:a 1} 99) {:d 4}]

nivekuil 2020-10-10T07:46:44.231300Z

aha, so that's what that does. I was confused as to how you get the whole map, but looks like that's what ?context is for. thanks

nivekuil 2020-10-10T08:01:49.231700Z

I saw it, but my brain is too slow at this time to understand it :) I am also too slow to understand why it only seems to match the first map, so it wouldn't work if I wanted to match on`:d`:

(m/match [1 2 {:a 1} {:d 4}]   
 (m/$ ?context {:d ?d})
 (?context (list {:d ?d} 99)))  
 => [1 2 ({:d nil} 99) {:d 4}]