Timeline for Why it is possible to specify a value comparer for ImmutableDictionary<TKey, TValue>?
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 17, 2020 at 21:14 | history | edited | Doc Brown | CC BY-SA 4.0 | deleted 28 characters in body |
| Dec 7, 2020 at 23:19 | comment | added | Enrico Massone | Anyway, I agree that the Dictionary<TKey, TValue> should allow the caller to decide how to compare values, in order to control the semantic of the ContainsValue method. | |
| Dec 7, 2020 at 23:16 | comment | added | Enrico Massone | See here docs.microsoft.com/en-us/dotnet/api/… for the details on the behavior of the SetItem method. | |
| Dec 7, 2020 at 23:16 | comment | added | Enrico Massone | I think that the APIs are different due to the interesting behavior pointed out in the link added as a comment to my question by Robert Harvey. In the case of ImmutableDictionary<TKey, TValue> the value semantic is relevant for the behavior of the SetItem method, in order to decide whether or not returning a new instance of the dictionary. This is probably the most relevant underlying cause of the different APIs. | |
| Dec 7, 2020 at 23:11 | comment | added | Enrico Massone | Viceversa, in the case of ImmutableDictionary<TKey, TValue> the method ContainsValue is implemented by using the value comparer provided when the immutable dictionary is created from the immutable dictionary builder. So, in the case of ImutableDictionary<TKey, TValue> the creator has full control over the value comparison semantic. | |
| Dec 7, 2020 at 23:08 | comment | added | Enrico Massone | I tend to forget the existence of ContainsValue simply because I rarely use that method. Most of time I'm more interested in ContainsKey. That said the symmetry that you pointed out totally makes sense. The documentation for Dictionary<TKey, TValue> states that the default equality comparer is always used for values (docs.microsoft.com/en-us/dotnet/api/…) | |
| Dec 7, 2020 at 21:23 | history | answered | Doc Brown | CC BY-SA 4.0 |