Open bencoveney opened 9 months ago
The point is to change the definition of "unique". Set's existing definition doesn't actually match the language's already - -0
and -0
are treated the same.
A significant part of me agrees that HashMap
or HashSet
might be good names for this; it's what other languages have. But I keep feeling like it's not quite right because:
Set
and Map
are not "hash maps" when under-the-hood they are.keyBy
function doesn't return a pigeon box hash, it doesn't reduce the domain size - it's more providing an "identity" but IdentityMap
is definitely a bad name and CustomIdentityMap
is a mouthful
Excuse me sticking my nose in 😄 I was having a read through and wondered whether this would feel right as an extension to
Set
. For example, in the README currently:This sounds at-odds to me with the basic description of a set.
The
keyBy
callback is effectively a hashing function, making Set behave like a Hashmap. For that reason, I would think alternative to this would be to add aHashmap
orHashset
collection instead, into which people could passJSON.stringify
or whatever hashing behaviour they would like.To me this would feel like a better conceptual fit. If I received a Hashmap from some calling code, I think I would be aware of the fact that Hashmaps make less guarantees around uniquess and could proceed with caution. If I receive a
Set
on the other hand, I may be less likely to question the uniqueness check and may be bitten bykeyBy
being configured in a way I didn't expect. Another way to say it would be thatSet
becomes less "trustworthy".The are some equivalents to this stuff in C#: Hashset and Hashtable. I bring them up as points of comparison, because: