[RFC][List/Assoc\unique]

php.internals

Ilija Tovilo

3 years ago
Hi everyone After the discussion on adding a new ARRAY_UNIQUE_IDENTICAL flag has revealed that most would prefer a new function I've decided to create an RFC for this. https://wiki.php.net/rfc/list_assoc_unique This RFC proposes adding two new functions, List\unique() and Assoc\unique() as alternatives using strict equality (===) semantics, the former discarding and the latter preserving keys. Let me know what you think. Regards, Ilija Side note: I *really* hope the discussion will be about more than just the namespaces.

Tim Düsterhus

3 years ago
Hi On 12/1/22 19:22, Ilija Tovilo wrote:
> https://wiki.php.net/rfc/list_assoc_unique > > This RFC proposes adding two new functions, List\unique() and > Assoc\unique() as alternatives using strict equality (===) semantics, > the former discarding and the latter preserving keys.
I believe this would be better solved as part of the more generic "expanded iterable helper functions" proposal (which I really hope makes it into a proper RFC that is accepted): https://externals.io/message/118896 Deduplication is reasonably well-defined for arbitrary iterators (even infinite iterators) and I don't think iterators (esp. Generators) should remain second-class citizens to arrays going forward.
> Side note: I *really* hope the discussion will be about more than just > the namespaces. >
In addition to the reasons above: Yes, adding two new single-function namespaces IMO is not a good thing, because it only adds to the inconsistency. Adding new namespaces should be part of a "bigger picture". Best regards Tim Düsterhus

=?utf-8?B?5rGf5rmW5aSn6Jm+5LuB?=

3 years ago
Hi Ilija, Thanks for the RFC. In general, I like the idea but there are certain things not clear to me. 1. What will happen if we pass a list to ` Assoc\unique`? ``` Assoc\unique([1, 2, 3, 1]); ``` 2. What will happen if the array (no matter list or assoc) contains pure value and reference which are strict equal? As the RFC says "references are preserved." ``` $a = 1; $arr1 = [$a, &$a]; $arr2 = [&$a, $a]; List\unique($arr1); List\unique($arr2); ``` 3. Currently the RFC (proposal section, function signature) claims the parameter are bool type, which is obvious wrong. But this is just a minor mistake, what I really want to ask here is do we support array only or any array like input?
> Side note: I *really* hope the discussion will be about more than just the namespaces.
Adding two new namespaces with single function doesn't look good to me, especially I cannot think of anything that we may add to these two namespace in the future. Regards, CHU Zhaowei