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
const UnmodifiableSetView.empty() constructor #20
Comments
|
wow, i didn't know that you could write |
i could add this constructor :) |
Normally you fork this repository, push the change to your fork, and then send a pull request here. |
ok, so i forked the repository and added a const constructor to UnmodifiableSetView Instead i could make my newly implemented class |
You can avoid that error by using a redirecting factory constructor, which is a little-known corner of the language useful for exactly this case. Basically you write const factory UnmodifiableSetView.empty() = _EmptyUnmodifiableSet; and that makes |
ok, that work if i also change |
|
but look at the definition of Set.remove, semantically trying to remove an element from an empty list simply returns advantage:
disadvantage:
It's your choice. |
The term "unmodifiable" has a very specific meaning in Dart, and especially in the context of this package. It means that all mutation operations throw—there's no exception based on whether the operation would actually change the state of a modifiable version of the class. I would expect any class with "unmodifiable" in the name to abide by those rules, whether it was attached to |
fair enough, the programmer in me understands (while the grammar nazi in me wants to point out that this very specific meaning of "unmodifiable" is different from the general meaning of "unmodifiable" :P . Yes, programming languages are less ambiguous than natural language, i understand). |
ok, i updated my code and added tests for
Is my next step the pull request? |
Yep! |
It would be really nice to have a const Unmodifiable{List/Map/Set}View.empty() constructor or Empty{List/Map/Set} classes with const constructor because only const values can be used as default arguments for optional parameters!
The is a const Iterable.empty() constructor in Dart:core, but the same for List/Map/Set is missing and the List/Map/Set.from{Iterable}(Iterable i) constructors don't help us because they aren't const.
The text was updated successfully, but these errors were encountered: