New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add note on collection equality on 'Collections' page #5629
Comments
This comment was marked as resolved.
This comment was marked as resolved.
==
in relation to collections
==
in relation to collections
@eernstg @munificent : Would you have any insight on this contributor's issue? |
First, I do agree with @dtonhofer that this topic merits an explanation. The way I usually respond when it is argued that collection equality should be based on the contents is that (1) we don't have a distinction between mutable and immutable collections at the level of types, and (2) mutable collections should have an equality which is based on object identity. Because of (1), it isn't practical to make a distinction between mutable and immutable collections when we're considering an expression that uses Item (2) is based on the consideration that it is misleading to report that two mutable collections are equal if they aren't the same object: They may contain equal elements right now, but they could differ at any point in the future if at least one of them is mutated. So we may give the developer the strict notion of equality which will actually remain stable over time, plus a notion of equality which is based on the current contents when that's appropriate. Given that object identity is the safe kind of equality it gets the operator You could argue that this choice is limiting because there is no way to specify that any given equality comparison should use one or the other (and there could be more than two) in a composite setting. For instance, we might want to compare two objects of type However, I think using identity based equality for collections and offering |
Page URL
https://dart.dev/language/collections/
Page source
https://github.com/dart-lang/site-www/tree/main/./src/content/language/collections.md
Describe the problem
On page collections one should highlight the fact that "equality of a collection" falls back to the default "object identity", i.e. using
==
on collections just checks whether the objects on the left and right of==
are "identical".The user might expect that
==
compares the collection contents, which would be:One might redirect the user to consult libraries such as quiver which provide appropriate facilities.
For fun, some example code I just wrote:
Expected fix
Update the page.
Additional context
No response
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: