clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
bocaj 2020-10-08T19:17:37.014Z

Maybe this is an idiom I need to learn: I’d like to compare 2 maps, where keys match, just like a join. However, I don’t want to compare using equality, but a function that outputs a number between 0 and 1. Maybe too abstract right now, but shout out if this is a familiar thing.

lodin 2020-10-08T19:53:45.016Z

@bocaj Sounds like you want to use merge-with, like (average (map #(if % 1 0) (vals (merge-with = m1 m2)))) (assuming you have an average function), if I understand you correctly.

bocaj 2020-10-08T19:54:10.016200Z

Ah, thanks!

bocaj 2020-10-08T19:54:57.016900Z

I’m working with 2 graphs, if that helps. Struggling a bit with the right structure

lodin 2020-10-08T19:55:19.017800Z

Make sure you have the same keys when using merge-with like that. It doesn't discard elements only found in one.

bocaj 2020-10-08T19:57:30.019900Z

{:name {:weight nil :val "jones"} {:name {:weight nil :val "jone"} I think I could use merge with to set the weight with the result of

(compare "jones" "jone")