meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
2020-08-28T14:17:00.200900Z

Hello, I have a noob question if you don’t mind. I have some code like this:

(def example {:a {:ret :int}
              :b {:ret :int}
              :c {:ret :bool}})
(reduce (fn [acc [k v]]
          (update acc k (fnil conj []) v))
        {}
        (m/search example
          {?v {:ret ?k}}
          [?k ?v]))
Which is a inversion of a map, sort of. I am wondering, is there some way to express this as a rewrite?

noprompt 2020-08-28T18:15:37.201900Z

Use group-by for this. 🙂

(let [example {:a {:ret :int}
               :b {:ret :int}
               :c {:ret :bool}}]
  (group-by first (m/search example {?v {:ret ?k}} [?k ?v])))

jimmy 2020-08-28T18:26:47.202800Z

Looks like those aren't quite equivalent. Going to take a look more at what is intended

jimmy 2020-08-28T18:35:58.204500Z

@jeremys In general, right now in meander if you want to group things, the general answer is to use clojures means of grouping.

jimmy 2020-08-28T18:36:09.204800Z

We hope to have a better answer in the future.

2020-08-28T18:56:31.204900Z

Thank you for the answer! It’s funny squinting at it, it looks like logic programming to me. I don’t know the cata operator yet besides the vague idea of recursion. Now I see a bit better how it works and the trick building the append` list to recur is neat. Wouldn’t have found it myself that’s for sure. Thanks

2020-08-28T18:59:12.206800Z

@jimmy Thank you, I’ll keep looking out to see what goodies you guys come up with. This project tends to dead/live lock processes in my brain but I find it very cool.