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

An implementation of Map. That allows for multiple inserts of a ke y … #47

Closed
wants to merge 2 commits into from

Conversation

rwrozelle
Copy link

…retaining all inserted values and always returning the last inserted value through standard Map API. Additional method, multiple, allows access to all inserted values for a given key. Will be used in http and http_server packages for non-breaking extension of functionality for form parameters and header parameters that have multiple values for the same key.

Referenced Issues:
dart-lang/http#47
dart-lang/http#24
dart-archive/http_server#35
dart-lang/sdk#28142

…retaining all inserted values and always returning the last inserted value through standard Map API. Additional method, multiple, allows access to all inserted values for a given key. Will be used in http and http_server packages for non-breaking extension of functionality for form parameters and header parameters that have multiple values for the same key.
@kevmoo
Copy link
Member

kevmoo commented Jan 4, 2017

@lrhn @nex3 thoughts?

@matanlurey
Copy link
Contributor

matanlurey commented Jan 4, 2017 via email

@lrhn
Copy link
Member

lrhn commented Jan 4, 2017

It doesn't sound like a safe approach.
It is basically introducing a subclass of Map that looks like a map, but which some methods can recognize and use the extended API of - without changing the type of the existing methods.
Which means that it's a Map that isn't really a Map, we just disguise it as one to get through the type-check, and then internally, it's treated as something different. Then it shouldn't be a Map at all.

It would mean that there is nothing in the type to suggest whether a class actually accepts and understands the "multi-map" - you can implement an interface that says that a method does, and just treat the argument as a normal map, and everybody seems happy.

I'd much rather prefer to actually have a real MultiMap type, and add methods that return or accept multimaps, or have methods that accept or create maps with iterables as keys (or either values or iterables).

@nex3
Copy link
Member

nex3 commented Jan 4, 2017

I like this design. It's a good fit for APIs that we have a strong need for in http and shelf.

@lrhn I don't think it's right to say that this isn't really a Map. It implements Map, and all methods that are part of the Map interface follow the normal Map semantics and operating on a single value per key.

I think there's a lot of benefit for APIs that declare Map as a type to handle MultiMaps gracefully, but the real benefit comes from the other direction: APIs exposing them to the user. Consider the case of HTTP request headers. Headers can have multiple values, but it's rare. Most of the time users want to interact with them as though they're a normal single-valued map. But we clearly also need to expose multiple values to users who need them.

This MultiMap design is perfect for that case. It follows the normal Map API for the common case, while also providing specialized multi-value APIs for users who need them. Exposing a separate parallel multiHeaders getter would provide a much worse user experience.

…gnment with Map API, so that extended use of "mulitple" capability must be explicit rather than implicit.
@rwrozelle
Copy link
Author

I've updated because I wasn't happy with my original code on the '[]=' operator. Decided it could introduce a breaking change if used in place of a Map as @nex3 intends. Are we at an impasse on this Pull Request? I'm obviously in alignment with @nex3, if it looks like a Map and acts like a Map, then its a Map regardless of the internals. To me this is the foundation of encapsulated programming. Multimap class is a specialized map that has additional capability. A separate argument could focus on the internals of the Multimap class and whether it is efficiently implemented.

@nex3
Copy link
Member

nex3 commented Jan 6, 2017

@rwrozelle I'll talk to @lrhn either here or over email and we'll figure out a way to do this that we're all comfortable with.

@matanlurey
Copy link
Contributor

I think we should consider closing this and revisit if it's not going in as-is.

@nex3
Copy link
Member

nex3 commented May 17, 2017

I'm still discussing with Lasse offline (although that got interrupted by my leave).

@rwrozelle
Copy link
Author

With this stalled, I moved my server side code over to Spring/Java, so I know longer have a pressing need to get this resolved.

@natebosch
Copy link
Member

Ping?
Does anyone still need this? Anyone prepared to take on the cleanup from quiver if this goes in?

@matanlurey
Copy link
Contributor

Closing. We can re-open if/when necessary.

@matanlurey matanlurey closed this Feb 20, 2018
@nex3
Copy link
Member

nex3 commented Feb 21, 2018

This is still something I'm interested in getting in place for representing HTTP cookies, but I haven't been good about following up on the discussion about it.

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

Successfully merging this pull request may close these issues.

None yet

7 participants