meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
2020-10-08T11:47:10.208Z

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 Wang 2020-10-08T12:02:18.208500Z

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

2020-10-08T13:10:55.209200Z

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

2020-10-08T14:24:53.211100Z

@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])

noprompt 2020-10-08T18:25:12.214500Z

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)

noprompt 2020-10-08T18:28:24.216400Z

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)

noprompt 2020-10-08T18:31:44.218100Z

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

noprompt 2020-10-08T18:34:17.219800Z

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

noprompt 2020-10-08T18:38:19.221800Z

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.

noprompt 2020-10-08T18:44:13.225300Z

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.

noprompt 2020-10-08T18:48:09.226900Z

What do y’all think?

1👍
2020-10-08T19:30:19.227800Z

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

noprompt 2020-10-08T20:01:59.228600Z

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

noprompt 2020-10-08T20:02:46.229Z

Not to say we don’t value veterans. 😉