Skip to content
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 map.keys() #14716

Closed
ben-albrecht opened this issue Jan 3, 2020 · 4 comments · Fixed by #14717
Closed

add map.keys() #14716

ben-albrecht opened this issue Jan 3, 2020 · 4 comments · Fixed by #14717

Comments

@ben-albrecht
Copy link
Member

ben-albrecht commented Jan 3, 2020

I find myself trying to use map.keys() quite often, both because of the symmetry with map.values() and my python background leading me to expect a similar interface to dict. However, this results in a not-so-great error message, because keys is an array field, not a method:

use Map;

var m: map(int, int);

m[1] = 2;

writeln(m.keys());
error: unresolved access of 'DefaultAssociativeDom(int(64),false)' by '()'

I am in favor of adding a keys() iterator to mirror the values() iterator. If not, we should at least add a better error message for this specific case.

@ben-albrecht
Copy link
Member Author

ben-albrecht commented Jan 3, 2020

Kind of a follow-on to #13624 after having more map experience under my belt.

@e-kayrakli
Copy link
Contributor

I think we should have keys.

Apparently, I said in #13624:

What should these yield? I am going the python way again and making it yield
keys. And adding items iterator to yield k-v tuples, values iterator to
yield values.

Reading this again, I don't know why I didn't add keys in the first place. I think that it was an oversight on my part to not add an iter keys() that is identical to iter these()

@bradcray
Copy link
Member

bradcray commented Jan 3, 2020

Only vaguely related, but recall that late discussion on issue #13624 also raised the question as to whether these() should behave more like items() and less like keys().

@e-kayrakli e-kayrakli mentioned this issue Jan 3, 2020
2 tasks
@e-kayrakli
Copy link
Contributor

@bradcray

Only vaguely related, but recall that late discussion on issue #13624 also raised the question as to whether these() should behave more like items() and less like keys().

I opened #14718 to summarize the discussion under that closed PR.

e-kayrakli added a commit that referenced this issue Jan 8, 2020
Add map.keys()

This PR adds `keys` iterator to `map`.

Resolves #14716.

[Reviewed by @daviditen]

Test:
- [x] standard
- [x] gasnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants