Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116583 Return-Path: <7snovic@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 34600 invoked from network); 7 Dec 2021 08:42:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2021 08:42:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6EA5518037F for ; Tue, 7 Dec 2021 01:42:32 -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-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 01:42:31 -0800 (PST) Received: by mail-io1-f49.google.com with SMTP id b187so16299901iof.11 for ; Tue, 07 Dec 2021 01:42:31 -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=LXGkXYILvAtAY2ucAOeLCx6VuWaUIT/cO36csadJQ+k=; b=EiRI61U1s0ZX80L0rUYM4d0XNYqgRbMQ93UxYZPBrtrCOnMtKTUGdmcz/LYxuMM1yj zyv5AUjoZ2jrcaZVr8j0mFuUIEKBZIbvAkLjvAU8kJbedAeLQQcgnKPGBblbGC8oV5v3 9hbQIk323znLN8eySzXn9qlUFmFgBTJnGj/DyB5+6rSbJgYp94s5DcWRpP9xp1TRUvRG YILdS5QBWIOpRutjdm1lHAnI9GUzAoFkE7zKRNPq1xmQuY1Bd8yuaHUDPJdycBJLf7i9 X3QSKHjkGCVTnNS7KnIei710eCdBKNJ5ynXSKsVszOI1CFkBG1sZbOPXj8xK+bd4h6Ur COlw== 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=LXGkXYILvAtAY2ucAOeLCx6VuWaUIT/cO36csadJQ+k=; b=x08c2T4tsIjr32fQt40DxHMofuzet5Yf5XtCdWuCzuoKTwTkBPKmKExgXdncxWxFS/ DHps2WT/5xi7X3ZtLTBBE7bcDqwsiDKK6pWZnwciJ/H98vJVT5kMAk6zrPVkfLT1nvZd RXOPD3tFv6sYyJF46fJ5r7JzcujQWT6hnJaZdQlkCapAFMkbBCEdDpTRwN6yitGvPZfh oFBdHrGS4wCSwskSbaRnWHHcDPRoDmVaefelul8Ch7I1qrbfOzJRiJnISEd7R/hcCFY2 djhKe0x/bHdYzsdD+4jq63lnzt9xQ1rQmsaZbZGrHRiA6blX52Rh7OpQstecedxILZD8 uUSA== X-Gm-Message-State: AOAM532f+ojnFTf66uX58JZj0PMXMptdnU2LvDO4w5FIGZQttBUXRln2 JdxAw+gL5q4AMW1wjdKowPEwPvR5PcrXXUZCTqgevpIGSqC9qw== X-Google-Smtp-Source: ABdhPJwv24fk8F3LwAtlDcD7eUaeaRDIicWC4eDLA3G0h5NP2u2T7/Fn6U7uydPolhMHUoJN7gornB3COS/4oiZNOXw= X-Received: by 2002:a02:ab8f:: with SMTP id t15mr50836561jan.147.1638870150815; Tue, 07 Dec 2021 01:42:30 -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> In-Reply-To: Date: Tue, 7 Dec 2021 11:42:19 +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) 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 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 >