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?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])))
Looks like those aren't quite equivalent. Going to take a look more at what is intended
@jeremys In general, right now in meander if you want to group things, the general answer is to use clojures means of grouping.
We hope to have a better answer in the future.
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
@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.