beginners

James Amberger 2025-08-01T20:44:01.757099Z

I need to compare some messy relational data and I’m looking for a data structure that is like a set, but compares elements according to a function other than = , such that

(conj
  (cool-data-structure :relevant-key #{{:relevant-key :A :other-key :value2} ... lots more like this})
  {:relevant-key :A, :other-key :DIFFERENT-VALUE}
  {:relevant-key :B, :other-key :whatever}
   ... again many more records
)
would produce
#cool-data-structure{{:relevant-key :A, :other-key :DIFFERENT_VALUE}
                     {:relevant-key :B, :other-key :whatever}
...}
I think this would be pretty easy to write but wonder if there is prior art

p-himik 2025-08-01T20:59:00.252099Z

I would most definitely avoid unnecessary complexity and just use a map here instead of a set.

☝️ 1
James Amberger 2025-08-01T22:32:10.364119Z

Based on what I’ve hastily written rather than what I intended, I think that’s good advice. I’m going to edit the OP

James Amberger 2025-08-01T22:43:04.479999Z

this looks pretty spot on https://www.mikkokoski.com/blog/set-custom-equality/index.html though varies slightly from my spec above by preferring the item already in the coll

p-himik 2025-08-02T18:25:31.167159Z

I still don't see how the edit affects my advice. Why would a map be a bad fit in your case? Or at least a worse fit than a whole custom data structure.