Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116586 Return-Path: <7snovic@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 14366 invoked from network); 8 Dec 2021 08:35:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Dec 2021 08:35:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D941718037F for ; Wed, 8 Dec 2021 01:35:24 -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-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 ; Wed, 8 Dec 2021 01:35:24 -0800 (PST) Received: by mail-il1-f182.google.com with SMTP id s11so1625870ilv.3 for ; Wed, 08 Dec 2021 01:35:24 -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=zsaVzkl6cSy0GFn3DNrsZxr/3jmFpS+BxtNRrEzOQnQ=; b=KJuOeIbwLVF4/UQmqzosWRwxs1S/2qBPMsI5hWKv9OyZ5+tVg5xknAPyZd+NT2tZBB ltCz11O7YIcjah1FTsXHxif3IUJYzplc5oty2JSy18Yk+9dPtQ5Cb1c24vzipb+RyMyp uN+VZoAl7HsiY/W1K7igQsLTNX5SBvnsdrZKVzWu5taKj9PBlN3NtAYxNeaPic89f5SV e6npVd6bkp27hqtaoqd41//aIJH0xKk+3S1jzqfZuNe2KirEgvtpLza+Y7PcfgBP7WBx ugsLC0POEwIgS139jCNmFuxSv9JAN67K/NaOpBlCHok1u4wHrTvzbbfOENP/HXSicZNH Eg2g== 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=zsaVzkl6cSy0GFn3DNrsZxr/3jmFpS+BxtNRrEzOQnQ=; b=F7BytJ7uVBhBy07KilZjwcrxdQTnRo4lGlafIUgcfx6MYx6sWZy1F+1xwSL/JCsuPj 8E0T50oa35mMZss9bEoWANbWM3vsgsRN2pg2GdjL21jaxPMy7k9BzsJSA1tNGSry1iwK kdPCRf3JXE2v59jBKu/yL0rwjUIFLeNJevqjvZ/s0pmCy9W61uHk5OxYv+x2scRUwVyh h60zISYsdOMMkO8oXSEnsdVT8CoAb8fk/9l/5p9mIYl+VXihn60d/4kXF+V225hkeZ9F rW273I9ztFuRc5aPl+swkMZL6G0zOGIJqNwdOrlaB/UNqVhO/79aSGwx5Fv859kYqEag 8U2w== X-Gm-Message-State: AOAM530MF4L9dzVebIzGAaqm6ML+NtA+o/6U3PP0zvk8g1k/QiPhojbq PkKV+sQWvFVXfolFUkz3S1ewgndFt5xVzvVz/eK0P+MnTRk= X-Google-Smtp-Source: ABdhPJyV1fF8DQverct3zPNFMp1fiVoV+B4fDFzKM5Tko7/wRoDwTxrfgqH9HJcTa9phqxX4eWp4zSp2taLtVgl6/M8= X-Received: by 2002:a05:6e02:1c45:: with SMTP id d5mr5020347ilg.56.1638956123723; Wed, 08 Dec 2021 01:35:23 -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: Wed, 8 Dec 2021 11:35:11 +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) 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 >