meander

wilkerlucio 2022-09-20T17:34:41.568749Z

hello, I'm trying to use a rewrite strategy, but I notice that different than when using find or search, I can't have a clojure expression replacement, for example:

(let [f
        (m*/bottom-up
          (m*/attempt
            (m*/rewrite
              {:all (m/pred some?) :as ?m}
              (dissoc ?m :all))))]
    (f {:foo {:all "here"}}))
=> {:foo (dissoc {:all "here"} :all)}

wilkerlucio 2022-09-20T17:35:03.694039Z

in this case I was trying to make a meander expression that removes every :all keys from all maps it can find

timothypratley 2022-09-21T15:32:45.455379Z

(let [f (s/bottom-up
          (s/rewrite
            {:all _ & ?m}
            ?m
            ?else
            ?else))]
  (f {:foo {:all "here"}}))
^^ this is how I'd do it 🙂

timothypratley 2022-09-21T15:33:18.389099Z

=> {:foo {}}

timothypratley 2022-09-21T15:34:37.575529Z

I think your version should work fine if you either used ~ to execute dissoc, or used match instead of rewrite

timothypratley 2022-09-21T15:35:17.597179Z

i.e.:

(let [f
      (s/bottom-up
        (s/attempt
          (s/rewrite
            {:all (m/pred some?) :as ?m}
            ~(dissoc ?m :all))))]
  (f {:foo {:all "here"}}))
=> {:foo {}}

timothypratley 2022-09-21T15:36:12.505999Z

But IMO the & thing is nicer as it keeps everything as a pattern 😉

wilkerlucio 2022-09-21T18:25:18.155149Z

gotcha, thanks you very much, works great 😄

👍 1
😎 1