Fork me on GitHub
#clojuredesign-podcast
<
2020-10-08
>
bocaj19:10:37

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.

lodin19:10:45

@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.

bocaj19:10:10

Ah, thanks!

bocaj19:10:57

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

lodin19:10:19

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

bocaj19:10:30

{: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")