Re: [heycam/webidl] More convenient way to refer to / use "map iterators" (#324)

> Yeah, for URLSearchParams you can have duplicate keys and the order between those duplicates is significant. For Headers you can have duplicate keys, but there it results in one key with multiple values.

That doesn't want to return a Map, it wants a MultiMap.  Since that doesn't exist in JS yet, you'll instead be returning an interface of your own, and the question of "what does it mean to return a map-sequence<>" is moot. (I'm not opposed to readying ourselves for such a future, tho.)

> Typically for these constructs you also want to support record<key, value> which can express less (only unique keys), but has more convenient syntax.

Yes, I'm handling that via a separate overload.  I don't think it's necessary or desirable to tie "takes a record<>" with "takes a map iterator"; for one thing, the former only accepts string types for keys, while the latter is free-form. (Since `record<>` becomes an Infra ordered map on the IDL side, and maplikes use an ordered map for their map entries, it's *super trivial* to initialize a maplike from a record, yay!)

> (And maybe `record<key, sequence<value>>`, though we haven't gone that far yet.)

And that seems to be handled reasonably by the existing signature and behavior.

> I think using map is a little wrong, something like key-value-sequence seems more accurate, and if we go there it should encompass all those input forms I think so we are somewhat consistent. (And then users need to deal with duplicate keys.)

Sure, kv-sequence works too. It's just that this particular pattern (an iterator of 2-tuples) is only really used by/for Maps, so putting it directly into the name makes sense to me. The structure is really awkward to author by hand, after all; it's nearly always going to be a Map iterator in practice anyway.

> This also seems like another case where you don't necessarily want it as return value, just as input.  But if it needs to be a return value, it should be a nested array or iterator for one I think, since that can encompass the full semantics.

Yeah, that's fine with me. It's trivial to load it back into a Map by just passing it to the constructor, and it's consistent with MultiMaps when those get reified.

---

So, let's assume that using `map-sequence<>` as a return value just returns an Array-of-Arrays; that's more general than using Map directly (and encourages returning maplike interfaces if that's really what you want).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/324#issuecomment-283443015

Received on Wednesday, 1 March 2017 21:39:26 UTC