On 20 November 2012 21:30, Tab Atkins Jr. <[email protected]> wrote: > On Tue, Nov 20, 2012 at 10:57 AM, Mark S. Miller <[email protected]> wrote: >> I think adding a MultiMap API to ES7 is a good idea. Neither Map nor >> MultiMap should be a subclass of the other, since neither is an LSP >> subtype of the other. > > When properly designed, as long as you interact with it only through > Map methods, a MultiMap can be an LSP subtype of Map. > > [...] > > The tricky part is dealing with .size and the iterator methods. You > need .size to reflect the number of keys, not pairs, to be consistent > with Map. But then .size doesn't match the length of the iterators > returned by .items() or .values(), unless both of these are changed to > only return the first value by default. (They can't return an array > of values, because that's not what Map does.)
If the multi map iterator returns the same key multiple times it already breaks the map contract. So you would need a separate iteration method for that. At that point, as Mark says, it is not clear what the benefit is. The proper approach would be to identify a common super class that identifies the commonalities. You could try to come up with a hierarchy of concepts, like they did for C++0X before it got downsized. But lacking types that hardly seems useful for JavaScript. /Andreas _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

