meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
timothypratley 2020-01-12T01:34:55.045Z

Hey! 🙂 I am trying to match a DataScript entity with a map and it does not. The reason is clear: (map? (d/entity db 1)) => false ; entities are not maps, but are map like: (associative? (d/entity db 1)) => true entities support a get interface which is sufficient to treat them like maps. One solution is to reify the entities into maps, but I’d rather not. Sadly entities are not seqable? (don’t ask me why not, seems silly). So maybe there is a missing concept here m/associative

👍 1
timothypratley 2020-01-15T20:29:11.060900Z

Any thoughts on the everything is a pattern webdev take? I extracted it to a more condensed macros and I think It’s pretty amazballs lol

(p/defview github-project-contributors-table
  ;; Justice pattern that queries for entities
  #:github.project{:name _}
  ;; A pattern to match the entities
  (#:github.project{:name !project-name
                    :contributors (#:github.user{:login !user-login
                                                 :name !user-name}
                                   ..!n)}
   ...)
  ;; Hiccup pattern of the view
  [:table {:style {:border "1px solid"}}
   [:thead
    [:tr
     [:th "Project"] [:th "Contributors"]]]
   [:tbody
    .
    [:tr
     [:td !project-name] [:td [:ul
                               .
                               [:li !user-name " (" !user-login ")"]
                               ..!n]]]
    ...]
   [:tfoot
    [:tr
     [:td.numeric "Total: " ~(count !project-name)] [:td.numeric "Total: " ~(count !user-login)]]]])
entities and patterns! seems way more obvious than what I’d normally do with for loops into vectors from maps or random stuff destructured here and there

1
noprompt 2020-01-15T23:39:54.061200Z

Thats pretty cool @timothypratley 🙂

noprompt 2020-01-12T01:58:32.046400Z

We might want to allow associative as an option passed via meta on the form.

timothypratley 2020-01-12T02:33:10.046600Z

That would be nice, and I do like that… but FWIW I’d still have to annotate every map in the pattern which would be tedious (though no different from writing m/associative so maybe more visually pleasing 🙂

timothypratley 2020-01-12T02:43:08.046900Z

https://github.com/timothypratley/pattern-query-view/blob/master/src/pattern_query_view/core.cljs ^^ FWIW I think this turned out pretty nice The only things I’m not satisfied with are: • The associative thing • I think combining the Justice query pattern with the meander match pattern would improve it • The listener mechanics aren’t perfect • I’m not sure Reagent is necessary, watching the @watch is a bit of a hack

😮 1
timothypratley 2020-01-12T02:44:09.047200Z

But I think the underlying philosophy comes through: There is a global DB You can query the DB with a pattern that looks like an entity You construct views with Meander patterns.

timothypratley 2020-01-12T02:45:29.047400Z

Just showing that it works:

timothypratley 2020-01-12T02:52:33.047800Z

Oh I could easily make a macro that annotated all maps as associative, and the idea is that this would all be presented as a simplified macro;; so the metadata approach wouldn’t be tedious and it makes sense that that would be a consumer concern (not a meander concern).

timothypratley 2020-01-12T03:01:54.048Z

FWIW I think m/associative is better than metadata though 🙂

timothypratley 2020-01-12T03:02:24.048200Z

It seems more analogous to m/sequable

timothypratley 2020-01-12T03:09:56.048400Z

and I can still do some magic macroing to translate maps to m/assocative forms mechanically.

timothypratley 2020-01-12T03:14:30.048600Z

Sadly I’m not sure how to implement it; it doesn’t seem as straightforward as m/seqable which just tests and seq … in this case something deeper needs to happen.

timothypratley 2020-01-12T03:24:39.048800Z

Worth considering the role that records play here too… presumably they are covered by associative, though you could get more specific an only match by type there too :thinking_face:

timothypratley 2020-01-12T03:31:49.049Z

i.e. coming from the other direction, maybe my match pattern should contain ->Entity records o_O that feels inconvenient, but is more explicit about what to match against.

noprompt 2020-01-12T04:10:17.050300Z

My suggestion was applied to the macro form e.g. match, find, search, etc.

noprompt 2020-01-12T04:11:53.052400Z

^{::m/associative-maps true} or something this affect. Of course, an operator is good too. 😄