-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Map's getKeys() / getValues() should be keys / values #1248
Comments
Added Area-Library, Triaged labels. |
Issue #1265 has been merged into this issue. |
This comment was originally written by ladicek@gmail.com While I'd love to have keys/values getters instead of getKeys()/getValues() methods, I have to point out that this:
actually doesn't seem to be true. The documentation doesn't contain any mention of the keys/values collections being backed by the Map, and they are not. See corelib/src/implementation/hash_map_set.dart -- both getKeys() and getValues() in HashMapImplementation are creating a new List and copying the keys/values to it, making it also O(N). |
This comment was originally written by @seaneagan Hmmm, since the API clearly takes its inspiration from Java, I just assumed. Here's why these methods need to return Collections backed by the Map:
new List.from(map.keys) // or The same arguments apply to making Collection#filter and Collection#map (issue #945) lazy. |
This comment was originally written by ladicek@gmail.com I agree that the collections of keys and values provided by the Map should be only a view on top of the Map, not a snapshot -- but that's probably worth another issue. |
This comment was originally written by @seaneagan Agreed, see issue #1305 ! |
This has been fixed with libv2. Added Fixed label. |
This issue was originally filed by @seaneagan
Map's getKeys() and getValues() return Collections which are backed by the Map, as in Java. This means none of the Map's keys / values are actually copied. Thus, these methods are O(1). Thus, they should satisfy all the criteria in the Dart style guide (http://www.dartlang.org/articles/style-guide/) for getters:
Not take any arguments.
Return a value.
Be side-effect free.
Be fast.
The obvious names for these getters are "keys" and "values".
The text was updated successfully, but these errors were encountered: