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 artI would most definitely avoid unnecessary complexity and just use a map here instead of a set.
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
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
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.