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

BuiltMap<String, BuiltSet<String>> updates #91

Closed
BlackHC opened this issue Jan 15, 2017 · 6 comments
Closed

BuiltMap<String, BuiltSet<String>> updates #91

BlackHC opened this issue Jan 15, 2017 · 6 comments

Comments

@BlackHC
Copy link

BlackHC commented Jan 15, 2017

How do I add an element to a contained BuiltSet?

MapBuilder does not allow me to retrieve elements and update them. Why is there no operator []?

Ideally, there was special casing for keys and values of BuiltMap such that toBuilder returned MapBuilder<String, ListBuilder> in this case.


What's a good workaround?

Right now, I've only been able to come up with:

BuiltMap<String, BuiltSet<String>> setMap;
String key, value;

setMap = setMap.rebuild((b) => 
    b[key] = (setMap[key] ?? new BuiltSet<String>()).rebuild((b) => b.add(value)));

Thanks,
Andreas

@davidmorgan
Copy link
Contributor

Ignoring the general problem -- shouldn't you be using a BuiltSetMultimap here?

@BlackHC
Copy link
Author

BlackHC commented Jan 20, 2017

Oh haha, yes, of course :D I feel like I might have contributed to the original implementation.

Not sure what to do about the operator [] though. I have run into this a couple more times. Usually I just end up setting the builder but access the built object. This is not optimal because I need to build it on every iteration to avoid staleness..

Maybe I should just use List etc within algorithms that calculate things. Somehow I like to stay within the Built* API though.

@davidmorgan
Copy link
Contributor

Yeah, it probably does make sense to add [].

@davidmorgan
Copy link
Contributor

I've also looked at special built collections that know they contain buildable values -- I think it's workable, but needing a new class name and needing more generics is a bit horrible. Also you need to supply a builder factory:

var listOfLists = new NestedBuiltList<BuiltList<int>, ListBuilder<int>>(() => new ListBuilder<int>());
listOfLists.buildAndAdd((b) => b..add(1));
listOfLists.rebuildAt(0, (b) => b..add(2));

Not sure it's worth it.

@ranquild
Copy link

Actually built list of built value classes is very common case. I would like to have that bridge between those two libraries.

@davidmorgan
Copy link
Contributor

Yes, I've been trying to think of a way to do that #83

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

No branches or pull requests

3 participants