meander

benny 2022-10-25T20:57:11.174189Z

Hey, I think I'm having a very basic question. I want to effectively keep a sequence a sequence inside a meander/match while rewriting the contents of the sequence. This is what I've got so far but it still needs post-processing (which I'm okay with doing in clojure code, but I feel like I'm missing a piece of meander understanding):

(meander/search {:foo 1
                   :bar 2
                   :baz 3
                   :lst [{:id 1, :name "a"}
                         {:id 2, :name "b"}
                         {:id 3, :name "c"}]}
    {:foo ?foo
     :bar ?bar
     :baz ?baz
     :lst (meander/scan {:id ?el-id
                         :name ?el-name})}
    {:example/foo ?foo
     :example/bar ?bar
     :example/baz ?baz
     :example/list [{:example.list/id ?el-id
                     :example.list/name ?el-name}]})

✅ 1
benny 2022-10-28T08:10:03.442419Z

Thanks @timothypratley!

😄 1
timothypratley 2022-10-27T01:35:56.968009Z

(m/rewrite {:foo 1
            :bar 2
            :baz 3
            :lst [{:id 1, :name "a"}
                  {:id 2, :name "b"}
                  {:id 3, :name "c"}]}
  {:foo ?foo
   :bar ?bar
   :baz ?baz
   :lst [{:id   !el-id
          :name !el-name} ...]}
  {:example/foo ?foo
   :example/bar ?bar
   :example/baz ?baz
   :example/list [{:example.list/id !el-id
                   :example.list/name !el-name} ...]})

timothypratley 2022-10-27T01:36:42.242299Z

=>

#:example{:foo 1,
          :bar 2,
          :baz 3,
          :list [#:example.list{:id 1, :name "a"} #:example.list{:id 2, :name "b"} #:example.list{:id 3, :name "c"}]}

benny 2022-10-25T20:58:44.454729Z

I would like the output to be:

{:example/foo 1, :example/bar 2, :example/baz 3
   :example/list [{:example.list/id 1, :example.list/name "a"}
                  {:example.list/id 2, :example.list/name "b"}
                  {:example.list/id 3, :example.list/name "c"}]}