Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116624 Return-Path: <7snovic@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 22374 invoked from network); 12 Dec 2021 11:38:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Dec 2021 11:38:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D894180211 for ; Sun, 12 Dec 2021 04:40:17 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: <7snovic@gmail.com> Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Dec 2021 04:40:16 -0800 (PST) Received: by mail-il1-f175.google.com with SMTP id m5so12595413ilh.11 for ; Sun, 12 Dec 2021 04:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JjDX8uoluGR/SX6k3SM8vV5RAPFG0mks+spNuKVs6xM=; b=XOosIZVEebsac60G1picAAhup8/hHtXNU2EXJd9eiKLPNy3DMfcRiuaJOmflVHA7Es EFPJjiQpHsa2A+s6L/Xd1qVIdSh9V0lxcBd6vEWW6ngJQDFBZi94xz5iVaLi4wf6ImUG g18WFPUBgK391zaq7S/Ve0gM5Flc7bxfwloO0FKeLlz0lgGCIDBkPuWdhQRw4uMe3pA/ 9UkuAr3v6vzwmt2YEXc4qOtpHkc7ZKXQYapCPoMUQ9alkE+GIrrosIVoq+cZb9whEuNI /EC66WcoqE7QbgPmujuldr5nj5DY3RWUGftmKX4C4BBf5ozWDTxaI10jFWiLlzjCEPYr jqKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JjDX8uoluGR/SX6k3SM8vV5RAPFG0mks+spNuKVs6xM=; b=A6MF3SNN86W41++gEtLpf2JBvkeJyv0PrUssKraUMd5aUVADP5/b/U79fXh+6gkVkh e4VBQDThcvx1g9Jh+pJW70aYYyyRxfeR0O5F3UIYnThA6HavCD9AYxYTJEbVIVN+aRIU KQ0Lbgos/a4Ff72T827K4TkSAkihL7ARGF2UgwqYvENDyB1qGA4RB6VrxR487CViYhG5 /1iRPWZR1KHcjaoY0MHBFsapQZi54nKXDDUhw0/eABUVVe0XjgxKwgGoIIyVt6YGozFM 8fcUkOzHW1aut5cgfTHtyhOBwYp/ozQ2RrMX7dZENiGHS5UdfGLw5G5kHva/+CApSw7j 1qqw== X-Gm-Message-State: AOAM532pgjNy7t8MXq8vj17EfYVZW1C+JndtnPeMS67FqmvpWSmeFpB0 puPifnxTgMDJavbKn+0b3h4ODyXwsucwarET2ZM= X-Google-Smtp-Source: ABdhPJyz86/QVh0DGi4CQxZHO48wMFO1X1oH1d0AefCxXgPRBlBOGByWiZgBxmUpBvR3561DxYc5W6/Vkaswzcfx2MM= X-Received: by 2002:a05:6e02:1c45:: with SMTP id d5mr28854517ilg.56.1639312816115; Sun, 12 Dec 2021 04:40:16 -0800 (PST) MIME-Version: 1.0 References: <61ac9759.1c69fb81.b0241.1e6fSMTPIN_ADDED_MISSING@mx.google.com> <268F5B4F-4770-48AA-B212-DE23116BCF4C@gmail.com> <2e4dd298-77a1-4c40-ba31-1c9b7ebe1bb1@www.fastmail.com> <1b5790ec-1ffb-461e-b3fc-91d59a6db831@www.fastmail.com> In-Reply-To: Date: Sun, 12 Dec 2021 14:40:05 +0200 Message-ID: To: Hendra Gunawan Cc: Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC [Discussion] array_column results grouping From: 7snovic@gmail.com (Hassan Ahmed) I already added a new function `array_group`, any further comments/thoughts will be highly appreciated. Regards, ~Hassan On Wed, Dec 8, 2021 at 11:35 AM Hassan Ahmed <7snovic@gmail.com> wrote: > > Hendra Gunawan IMHO your suggestions is not related to > `array_group()`, you are talking about a great change in PHP as > mentioned by Larry, since we can have `Array($input, group(), > reducer(), mapper(), filter() ..... and so forth);` or even any other > way to handle the list comprehensions. but for array_group I think > that we should keep it to the minimal, to only group array. > > ~Hassan Ahmed > > On Wed, Dec 8, 2021 at 1:26 AM Hendra Gunawan > wrote: > > > > > > > > And if you want to map, reduce, or filter without grouping? Then you can't > > > really use this function. And as noted, the order in which you apply those > > > operations may matter, and no order is necessarily more obvious or beneficial > > > > You can modify it slightly if you eager to: > > > > array_group( > > ... > > null|int|string|array $index_key, > > ... > > ): array > > > > If You provide `null`, it will operate on a bare array, no grouping involved. > > As a consequence, users have to provide `reducer` or `mapper`. So virtually, > > You design `array_group` to swallow `array_reduce` and `array_map`. Though, > > `array_map` is actually a different API compared to `array_reduce` or > > `array_group`. > > > > Interestingly, you will get a better quality of code if you include `reducer: ` > > and `mapper: ` consistently, whatever array level you work with. > > > > // `array_reduce` and `array_map` alternative > > array_group($array, null, reducer: $fnReducer); > > array_group($array, null, mapper: $fnMapper); > > > > array_group($array, "level1", reducer: $fnReducer); > > array_group($array, "level1", mapper: $fnMapper); > > array_group($array, ["level1", "level2"], reducer: $fnReducer); > > array_group($array, ["level1", "level2"], mapper: $fnMapper); > > > > I hope there is no bias between the proposed name (`array_group`) and its > > functionality. > > > > > > > > Either of these approaches would be superior to cramming more functionality > > > into a single-purpose function to turn it into a single-function swiss army > > > knife: > > > > Not a swiss army knife, just a penknife. AS i wrote before, it is just a > > shortcut. If you really mind about that, we can cancel `filter` and `sorter`, > > leaving only `reducer` and `mapper`. Thought, we can filtering and sorting > > before `array_group`, but i don't know whether it is as accurate as embedding > > them into `array_group` or not. If not, we have to iterate manually, do > > filtering and/or sorting, then reducing/mapping. > > > > > > > > https://wiki.php.net/rfc/comprehensions > > > https://wiki.php.net/rfc/pipe-operator-v2 > > > > Of course these are wonderful proposals. Yes, they are superior. To be honest, > > I really hope they are landed in PHP. I already imagine what part of my code > > will be replaced by them. Since I am not a C coder and totally blind about the > > engine, I don't have my own opinion whether we lost good things or not, by not > > adding them to PHP. > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > >