Fork me on GitHub
#meander
<
2020-10-08
>
mac11:10:10

Hey all. Very impressed my meander. I am currently using $ to find matching submaps. In that connection I would like to be able to capture the "path" to the matching maps, path in this case being not only the keys but the complete "super" maps of the match. Any recommendations on how to achieve this?

Lucy Wang12:10:18

maybe with m/cata?

(m/search {:user {:name {:first "Jack" :second "Lee"}}}
  {:first (m/some ?first) :as ?full}
  ?full

  {?k (m/and ?v (m/cata ?vv))}
  [?k ?v ?vv])
;; => ([:user
;;      {:name {:first "Jack", :second "Lee"}}
;;      [:name {:first "Jack", :second "Lee"} {:first "Jack", :second "Lee"}]])

mac13:10:55

@wxitb2017 Thanks a lot, I will give that a look.

mac14:10:53

@wxitb2017 I think I understand how this works. Some of my maps have sequences of maps as values. I tried the below to accommodate for this, but it does not appear to work.

(me/search
     {:user {:name {:first "Jack" :second "Lee" :addresses [{:main "test"} {:secondary "test1"}]}}}
     {:main (me/some ?main) :as ?full}
     ?full
     (me/scan {?k (me/and ?v (me/cata ?vv))})
     [?k ?v ?vv]
     {?k (me/and ?v (me/cata ?vv))}
     [?k ?v ?vv])

noprompt18:10:12

m/$ uses a zipper when context-pattern is passed

(m/$ ?context-fn ?pattern)
I suppose we could “unshift” another arity for capturing the path when matching an, pending a sensible definition, ignore it during substitution.
(m/$ ?path ?context-fn ?pattern)

noprompt18:10:24

Alternatively, the ?path parameter could be “pushed”

(m/$ ?context-fn ?pattern ?path)
or, if it makes sense, we could accept and parse keyword arguments
(m/$ ?context-fn ?pattern :path ?path :left ?left :right ?right)

noprompt18:10:44

Of course, we would ensure the getting the values/locations would be a safe operation.

noprompt18:10:17

In terms of flexibility/maintainability, keyword arguments are the most appealing because we can incrementally add all this functionality.

noprompt18:10:19

m/$ is meant for situations where you don’t know where something is so I think adding a way to capture more contextual information would be useful.

noprompt18:10:13

I think if we can come up with a sensible semantic for substitution with these additional parameters, we’d have a powerfully succinct but blunt force way of getting common tree rewrites off the ground.

noprompt18:10:09

What do y’all think?

👍 3
mac19:10:19

@noprompt I am an absolute newb when it comes to meander, but it sounds good to me.

noprompt20:10:59

@mac Newbies tend to have the most affect and influence on the project. 🙂

noprompt20:10:46

Not to say we don’t value veterans. 😉