meander

shane 2024-09-26T15:03:20.424849Z

hello - just starting to use meander and while I find it very impressive I still have no idea what I'm doing. Is there a way to group on an output variable? I have a map of route data that I would like to transform into a vector of route data. The results I get now work but they create a new route for each method instead of grouping everything under the path. Is this possible to do with meander?

(m/rewrites {:routes {"/test/:id" {:get {:request "..."
                                    :response "..."}
                              :post {:request "..."
                                     :response "..."}}
                 "/new/:id" {:get {:request "..."
                                   :response "..."}
                             :post {:request "..."
                                    :response "..."}}}}

              {:routes {?route {?method {:request ?req-opts
                                         :response ?res-opts}}}}
              [?route {:conflicting true
                       ?method ~(handler ?req-opts ?res-opts)}])

;; output looks like this:
(["/test/:id" {:get "..."}] 
 ["/test/:id" {:post "..."}] 
 ["/new/:id" {:get "..."}] 
 ["/new/:id" {:post "..."}])
  
;; i'd like for it to look like this:
(["/test/:id" {:get "..." :post "..."}] 
 ["/new/:id" {:get "..." :post "..."}])

noprompt 2024-09-26T17:08:03.244459Z

You can use a memory variable to collect stuff (`!xs` ) but note in the case of rewrites you will want to us ~!xs if you want the vector itself (`search` might be a better choice here since your right-hand side intends to call a function anyway).

noprompt 2024-09-26T17:09:10.290149Z

Memory variables also have broken semantics on the RHS for rewriting. 😄

shane 2024-09-26T17:31:04.704529Z

how could I use memory variables in this case? I've tried using them on !route and !method but I still end up with 4 outputs, just with a bunch of single entity vectors:

([["/test/:id"] {:conflicting true, [:get] ...}]
[["/test/:id"] {:conflicting true, [:post] ...}]
...)
 

shane 2024-09-26T17:45:28.214239Z

found this issue that seems to be the same problem - a lot of syntax I don't understand but might be able to reverse engineer it: https://github.com/noprompt/meander/discussions/222

noprompt 2024-09-26T17:12:45.162459Z

FWIW/FYI: I haven't been supporting my Clojure libraries because my day-job is mostly Python. 🙂

shane 2024-09-26T17:42:36.189399Z

Do you envision a meander-py being possible? working with a bunch of python devs right now who spend a LOT of time essentially writing json -> json ETLs that could easily be handled by meander.

➕ 1
noprompt 2024-09-27T01:34:08.402709Z

Actually, one of the first things I did when I got into Python (had to because ML/AI) was implement the fundamental building blocks of a system like it. Of course, you don't have macros but you also don't technically need them. I'm currently not doing much ETL so I haven't felt the need to really work on it. Python also has decent structural matching support nowadays. I use match a lot. And you can make simple rewrite rules with the pattern of

def some_rule[A, B](data: A) -> B:
  match data:
    case {"some_key": str() as some_str}:
      ...
And then compose. Not pretty but it works. match is new in Python and many people don't use it or are not aware of it. Are the devs you know comfortable with Python's match? If not, that'd be a place to start with immediate benefits.

❤️ 1
noprompt 2024-09-27T01:35:10.704859Z

All said, I recently had a few experiences where I wish I had something like Meander so I'll probably make time to build something eventually. For example, I built a prototype of single file components (SFCs) like Vue but for Python (because every Python templating language is some how horrible, and HTMX is fine for like 90% of the things you'd ever want to do on the front end). I think the compiler code would benefit from rewrite rules.

noprompt 2024-09-27T01:35:46.544179Z

Personally, I've wanted to avoid doing open source work but I also feel like I don't want to keep these things to myself. The Python SFC thing has made me way more productive and I could see other people finding happiness using it. I just have to be up front with people about my time.

🆒 2
noprompt 2024-09-27T01:39:25.976549Z

I'm also happy to just give people code and tell people what I know about how to build these things. At the core, what's driving Meander is pretty simple.

❤️ 1
2024-11-05T12:50:50.117649Z

@noprompt Thank you for meander. Started using it this weekend to extract data from excel table. So good !

🙂 1