meander 2023-08-30

how would I get

{:title "title"
 :foos [1 2]}
from something like this
(mean/search
    {:title "title"
     :items [{:foo 1} {:foo 2}]}
    ;; wrong
    {:title ?t
     :items (mean/scan {:foo ?x})}
    {:title ?t
     :foos ?x})

Probably with m/rewrite and a memory variable !x

I’m on mobile atm.

(m/rewrite {:title "title"
            :items [{:foo 1} {:foo 2}]}

  {:title ?title
   :items [{:foo !foo} ...]}

  
  {:title ?title
   :foos [!foo ...]})

;; =>

{:title "title", :foos [1 2]}

ah, rewrite. so that's a purely syntactic transform; if you want to map over the !foo s do you inline your logic as if it were match/search and then eval after, or do you do that outside of rewrite

Depends on what you want to do with !foo. If you want to just apply a function you can do something like this

(m/rewrite {:title "title"
            :items [{:foo 1} {:foo 2}]}

  {:title ?title
   :items [{:foo !foo} ...]}

  
  {:title ?title
   :foos [(m/app inc !foo) ...]})

💯 1