Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116585 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78863 invoked from network); 7 Dec 2021 22:26:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2021 22:26:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DBA6118037F for ; Tue, 7 Dec 2021 15:26:35 -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: Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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 ; Tue, 7 Dec 2021 15:26:35 -0800 (PST) Received: by mail-qv1-f53.google.com with SMTP id m17so808549qvx.8 for ; Tue, 07 Dec 2021 15:26:35 -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=gwzQMkZtX2n3IDZaN7zVWBY8D7Pw7ex5w7p3hBwSx0o=; b=XsK0H9d9Sr6fLhZVzO+F0DUnbq6bnWNpQey/mfVT+OnAuv4NUxd8WeVy8jI0OjNxOP Cyih9cl6xXVu2QsXuGEYcBc8nRhyRUmhKKYIqd5dlRYoGL75o+EjxKq7h4DR/8+R8PMB mKUpmHm8AL7KzEKLhXxSwWbj9JZMEYRDO2oin4K7vFMDf68p7fwzn9r6TNECbDh5Ribe 0uavl/68KGn+WOkLHL4ST2nLJ+LvniO5/bPuz1G/EXy1vrWO5dLHZIW38DelNt1beNNb 2BjeVlbd2XPkBeKOWpKDQEN+FZ5jqpI5PicJqnC7ebM/jPOzIQsf2fV/A2TKPVwgvRqC 4ffw== 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=gwzQMkZtX2n3IDZaN7zVWBY8D7Pw7ex5w7p3hBwSx0o=; b=hfAzeo5NOa6ow4vUiHqyhMW68bLp0szYDikVK2IConRyMkYsKtQlykdhE6Q2t/0+MP D6bnTdN4KNBxBzoL6ikBI5MPBV86p71xkkNbSHttAMRKbII91jkzYgLobAyTuS/KkJiS S5u0zsYhtnYeb9mST4XnsZ7jTFA+xzENi2zMVfSO4NvcP1zoYzuJ4hhegrl5Q2jHB6tO 3hXtE2a8uDxUmaI8GyGYCGBwRtLrkxtA2bXYrhcS7ZEYLZ2KG2CbErLDSMFzxdhyS0Gp 9Gwt6hOjb8BhaU0aBZKe2D16yLowx1ZpJuQw3LVJIsm3jWt36dVgOtf1GCuC2IYIcABj jS6w== X-Gm-Message-State: AOAM531I+pfEBg1bkJcBUR5fxOt8A+GFbZKlYZtRGCRMm1zvyCBycPoA FRjSrxEXrVPOhdSfLYCkmuEpM5H2nhjdMZEQgxoICaa+rlHdgA== X-Google-Smtp-Source: ABdhPJxgmxxVsXH3t6RagKMhOkO5EfY23BBfCE4fkkFuwtbI20eP7+cJjf+ohwiGVqNAKNNcvxAMpOGMkm7fKLdffM0= X-Received: by 2002:a05:6214:481:: with SMTP id ay1mr3148035qvb.108.1638919594671; Tue, 07 Dec 2021 15:26:34 -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: <1b5790ec-1ffb-461e-b3fc-91d59a6db831@www.fastmail.com> Date: Wed, 8 Dec 2021 06:26:23 +0700 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC [Discussion] array_column results grouping From: the.liquid.metal@gmail.com (Hendra Gunawan) > > 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.