Re: RFC [Discussion] array_column results grouping
| From: | Hassan Ahmed | Date: | Tue, 07 Dec 2021 09:42:19 +0000 |
| Subject: | Re: RFC [Discussion] array_column results grouping | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116583@lists.php.net to get a copy of this message | ||
This is a great suggestion Hendra, I really believe that it may take
the new function to another level, but - with Larry's comment in mind
- this is a language design more than function design. Supporting the
list/array comprehensions will be a great step for PHP, as I can
remember that Nikita already implemented something like this
https://github.com/nikic/scalar_objects as a
workaround but I am not
sure why does this was not implemented in the core yet. Almost all of
the array_* family functions - including array_column - can be
achieved by a
foreach call. so I do not believe that we need to
decline the new function and maybe in the future, we can add more of
your suggestions for it. especially the map parameter which IMHO is
a promising addition, it can be a mixed argument [ string, array,
callable ]. BTW your thoughts led me to change the order of the
arguments for the new function to be `array_group($array, $index,
$columns)` I will update the RFC with this.
~Hassan Ahmed.
On Tue, Dec 7, 2021 at 5:01 AM Hendra Gunawan
<the.liquid.metal@gmail.com> wrote:
>
> >
> > Better map/filter/reduce primitives in PHP would be dandy, but they have
> > nothing to do with array grouping. They're a separate operation that should
> > be composed with grouping. Packing them all into a single function sounds
> > like a terrible idea.
> >
> > If we wanted that... that's called list comprehensions, which I would
> > support and even tried to rally support for a few years ago, but got met
> > with a big shrug. :-)
>
> array_group is just a simple handy tool which can manipulate a
> bunch of data
> without touching SQL, DQL, query builder, or any producer anymore just to align
> the output to the need.
>
> Of course we can code with whatever programming paradigm or style we want,
> especially if the algorithm is much more complex. Here, i offer you the very
> basic functionality and without external library. So my coworker does not have
> to dig into that library, or ask me.
>
> The original proposal is to offer grouping, and may be to avoid
> foreach.
> I think if the only purpose is to group an array, it is halfly baked function-
> ality. Previously, I had shown you that foreach is not too bad
> to use.
> Otherwise, I will suggest to the author don't bother with new function, you're
> wasting your time. With that original proposed functionality, We have to use an
> additional foreach or function call even though it is a basic
> operation.
> Moreover, the original purpose is preserved, if we do not give any optional
> params.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>