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

Convenience initializers for map and set #22776

Open
Iainmon opened this issue Jul 19, 2023 · 1 comment
Open

Convenience initializers for map and set #22776

Iainmon opened this issue Jul 19, 2023 · 1 comment

Comments

@Iainmon
Copy link
Contributor

Iainmon commented Jul 19, 2023

It would be nice to have many constructors for map, set, and list that accept a variety of equivalent representations of the data structure. Such as

var ages = [
    ("Iain",21),
    ("Kassia",20),
    ("Nick",23),
    ("Saul", 82),
    ("Martin", 55)
];

proc map.init(entries: [?d] ?t) {
    type kt = entries.first[0].type;
    type vt = entries.first[1].type;
    this.init(kt,vt);
    for (k,v) in entries {
        this[k] = v;
    }
}

var ageMap = new map(ages);

and overloaded operators like

ageMap += ("Cray", 51);
ageMap += [(k,v) in ageMap.items()] ("_" + k,v);

list has some convenient initializers, and it would be nice to extend that to map and set.

@mppf mppf changed the title Richer API for data structures in the standard modules Convenience initializers for map and set Jul 20, 2023
@lydia-duncan
Copy link
Member

We actually removed some operator definitions that took another map as an argument, over confusion about what should happen when keys existed in both maps involved in the operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants