- From: Marcos Cáceres <notifications@github.com>
- Date: Tue, 20 Dec 2016 15:00:06 -0800
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/90/268384396@github.com>
> Another thing I was thinking, for a multimap you might want append() and such to return something indicating whether the multimap already contains the key being appended. That seems to duplicate what `.has()` and `.contains()` is for - or possibly even `.getAll(item).length`. > It's not clear to me what utility returning this offers and the Twitter poll doesn't really address that point either. It's what @jussi-kalliokoski said on Twitter: "consistency and least surprise". The current design violates both, because: 1. Consistency: it's inconsistent with the language primitives (map and set). 2. Least surprise: it's surprising that it doesn't return self, particularly when performing a `reduce()` as per the code below (which goes to argument of utility). Consider again what we have today: ```JS .reduce((params, url) => { params.append("foo", url); return params; }, params) ``` So, the utility in returning self is that `.reduce()` expects the "collector" to be returned. Thus, returning `this` would be idiomatic because it would work like regular maps and sets: ```JS // Look ma! no return keyword and no "{" or "}" .reduce((params, url) => params.append("foo", url), new URLSearchParams()) ``` It's extremely common to want to `.map()` a list of things, and then `.reduce()` those things into a collection type, like `URLSearchParams`, `DOMTokenList`, `Headers`, etc. but it's *surprising and inconsistent* that doing so don't follow ES. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/90#issuecomment-268384396
Received on Tuesday, 20 December 2016 23:00:41 UTC