Fork me on GitHub
#meander
<
2022-10-25
>
benny20:10:11

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
benny20:10:44

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"}]}

timothypratley01:10:56

(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} ...]})

timothypratley01:10:42

=>

#: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"}]}