Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-06-01 Thread Casper Langemeijer
On Thu, Jun 1, 2023, at 11:56, Boro Sitnikovski wrote: > Thank you for the suggestion, I like this approach and it's definitely much > "safer" than going with an RFC for core directly. > > What are your thoughts on creating a PECL extension called `array_utils` > (selling point would be high per

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-06-01 Thread Boro Sitnikovski
> On 1.6.2023, at 09:18, Casper Langemeijer wrote: > > On Thu, Jun 1, 2023, at 01:19, Boro Sitnikovski wrote: >> Thank you for the information and encouragement! I was a bit scared of this >> one being rejected too, but still decided to give it a shot :) > > As an alternative approach this i

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-06-01 Thread Casper Langemeijer
On Thu, Jun 1, 2023, at 01:19, Boro Sitnikovski wrote: > Thank you for the information and encouragement! I was a bit scared of this > one being rejected too, but still decided to give it a shot :) As an alternative approach this is what I would do in your situation: I would start with a PHP im

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Boro Sitnikovski
> On 1.6.2023, at 01:13, Levi Morrison wrote: > > On Tue, May 30, 2023 at 5:35 AM Boro Sitnikovski wrote: >> >> Hello all, >> >> As per the How To Create an RFC instructions, I am sending this e-mail in >> order to get your feedback on my proposal. >> >> I propose introducing a function t

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Levi Morrison via internals
On Tue, May 30, 2023 at 5:35 AM Boro Sitnikovski wrote: > > Hello all, > > As per the How To Create an RFC instructions, I am sending this e-mail in > order to get your feedback on my proposal. > > I propose introducing a function to PHP core named `array_group`. This > function takes an array a

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Boro Sitnikovski
> On 1.6.2023, at 00:59, Larry Garfield wrote: > > On Wed, May 31, 2023, at 10:47 PM, Boro Sitnikovski wrote: > >> 1. The grouping that JavaScript/.NET/Lodash/Scala/etc. do (this should >> be the default of `array_group`) >> 2. The grouping that Haskell does, the one I proposed earlier (this

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Boro Sitnikovski
> On 31.5.2023, at 09:03, naitsi...@e.mail.de wrote: > > > > Am 30-May-2023 18:34:19 +0200 schrieb andr...@dqxtech.net: >> On Tue, 30 May 2023 at 18:27, Boro Sitnikovski wrote: >>> >>> Hi, >>> >>> Thank you for your thoughts. >>> I would say the more common desired behavior is the on

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread mickmackusa
As an answerer and curator of many [php][arrays][grouping] tagged questions on Stack Overflow for several years, I'd like to mention that developers' non-SQL grouping needs are much more nuanced than merely defining group qualification and creating subarrays. Often devs will want to sum, count (in

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Rokas Šleinius
On Wed, 31 May 2023 at 10:30, Aleksander Machniak wrote: > > On 30.05.2023 13:34, Boro Sitnikovski wrote: > > I propose introducing a function to PHP core named `array_group`. This > > function takes an array and a function and returns an array that > > contains arrays - groups of consecutive elem

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread Aleksander Machniak
On 30.05.2023 13:34, Boro Sitnikovski wrote: I propose introducing a function to PHP core named `array_group`. This function takes an array and a function and returns an array that contains arrays - groups of consecutive elements. This is very similar to Haskell's `groupBy` function

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-31 Thread naitsirch
Am 30-May-2023 18:34:19 +0200 schrieb andr...@dqxtech.net: > On Tue, 30 May 2023 at 18:27, Boro Sitnikovski wrote: > > > > Hi, > > > > Thank you for your thoughts. > > > > > I would say the more common desired behavior is the one in your first > > > example. And even for that we don't have a nat

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Boro Sitnikovski
> On 30.5.2023, at 21:56, Andreas Hennings wrote: > > On Tue, 30 May 2023 at 19:25, Boro Sitnikovski wrote: >> >> Here's some more examples: >> >> 1. Use `array_group` to create list of singleton list: >> ``` >> $groups = array_group( $arr, function( $p1, $p2 ) { >> return false; >> } ); >>

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Boro Sitnikovski
> On 30.5.2023, at 19:21, Larry Garfield wrote: > > On Tue, May 30, 2023, at 4:27 PM, Boro Sitnikovski wrote: >> Hi, >> >> Thank you for your thoughts. >> >>> I would say the more common desired behavior is the one in your first >>> example. And even for that we don't have a native function.

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Boro Sitnikovski
Hi, > On 30.5.2023, at 18:33, Andreas Hennings wrote: > > On Tue, 30 May 2023 at 18:27, Boro Sitnikovski wrote: >> >> Hi, >> >> Thank you for your thoughts. >> >>> I would say the more common desired behavior is the one in your first >>> example. And even for that we don't have a native func

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Larry Garfield
On Tue, May 30, 2023, at 4:27 PM, Boro Sitnikovski wrote: > Hi, > > Thank you for your thoughts. > >> I would say the more common desired behavior is the one in your first >> example. And even for that we don't have a native function. > > This Google search might give more insight into the number o

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Andreas Hennings
On Tue, 30 May 2023 at 18:27, Boro Sitnikovski wrote: > > Hi, > > Thank you for your thoughts. > > > I would say the more common desired behavior is the one in your first > > example. And even for that we don't have a native function. > > This Google search might give more insight into the number

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Boro Sitnikovski
Hi, Thank you for your thoughts. > I would say the more common desired behavior is the one in your first > example. And even for that we don't have a native function. This Google search might give more insight into the number of discussions about a grouping functionality: https://www.google.co

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Andreas Hennings
Here we go, https://3v4l.org/KsL3o function array_group(array $arr1, callable $compare): array { $groups = []; $group = []; $prev = NULL; foreach ($arr1 as $value) { if ($group && !$compare($prev, $value)) { $groups[] = $group; $group = [];

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Andreas Hennings
Thank you, this clarifies and it confirms my initial assumption of what you are proposing. So you want to slice an array by comparing adjacent values. My personal feedback: I think the need for the grouping behavior you describe is not common enough that it needs its own native function. I would

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Boro Sitnikovski
Hey, Thanks for the suggestion. For the previous case in the code, I added these in a Gist to not clutter here too much: 1. The first example corresponds to https://gist.github.com/bor0/b5f449bfe85440d96abd933b9f03b310#file-test_manual_group-php 2. The second example corresponds to https://gi

Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group`

2023-05-30 Thread Andreas Hennings
Hello Boro, I think you should include the "expected result" in your code examples. Maybe this is in your patch file, but I don't think we want to look at that for discussion. Cheers Andreas On Tue, 30 May 2023 at 13:35, Boro Sitnikovski wrote: > > Hello all, > > As per the How To Create an RFC