Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118896 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98683 invoked from network); 28 Oct 2022 13:45:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Oct 2022 13:45:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 910471804BA for ; Fri, 28 Oct 2022 06:45:09 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_HOTMAIL_RCVD2, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2030.outbound.protection.outlook.com [40.92.22.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 28 Oct 2022 06:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzXFYh6oFjLSy7EQFikYsjVGLQnYsVE4UECdrlJ++68kWt/cmwZ/h5EOOZgxQza0zS7aVw2M674xZjt+1W3AzZOIVRoLRArCE1lSb/J8H24m5dl7BUzzAT4JqWpvCPUsezlEQFzG46Ga/WQfYK8mTccndNHYrVPTEW/7L0Rlpqn8BvRsiJTLI4ZP3w2N34zjr3kjH/QDKYc6moQ+t9O2Nq3WerqfwDzroLBqBzCKkBW+nrWtQHd9yYXXK2oUJcWIZErvHfQsfSgyVMtwNl3D/6Z+T/m6syiNhoNVy1iEoSmjHK7rOE6aM3xRopnDdlblf+3RUnHjVuUXWOzypzEwDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=a0eTM776PHtnXCtuMu9BjK+2+etHfwHve5s0mcDxr/0=; b=jX+lWsUETQIRG1JgEs3PfkRjtjJp2VL9hdPwxxgaXTc5baNV3u1KvIVgsGbi8Mam6p2A29wi+fnOzATF4UqYnH0/kpoXsXIrITXpwobNUOUdeHqpE39grvsU1ugu9YYKtb+A8AOFTj9tdHl2zfhciEn0ivTJKJyX+cJCSyH5aHdsn1qGmMiGV8o2oEzDgf+lP8Pb4tUkJlokudVBQfrCxatKcS7LsvyAQ+y4c6lubxdr/tbW9ZcREYF7uRH/KMOgtvBsn/+DPyc8vkAbqti1bwOMG2wdLdLWeiOBaW0drBYdzVRtbGTW+1d8KXA1CEuVORUxD8r4w/5M7Rp7/bWmdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a0eTM776PHtnXCtuMu9BjK+2+etHfwHve5s0mcDxr/0=; b=OYH0Q0AqS83VCWH8XEXUsgOljoQbUH0uP/o/Ucr+6py1Xpzy8SdcjXX/0yywgrGvMgdJ1WDLb23cxol2Uuf8aPJW2sgWXn3NPxVb/Wy/HEsREItt1vDeWL0m4+2xvNSM8D89rs0IQzYCNc5J9e56fbszwe0jVqphal4o1e0UPoSzitCAzbBMqo+m5Rv2Z1xlWj5UjBLkAfJLuuL9aKu8sOuxyAo+wmfBEMVDrQyvpPytf/AayIATZIqr8PZ+fUbcRFH+V1BQu4cSi/brhkrfBQKU94/h49W5MsD/WuBBajMvRqLNq68UT17FOfrVIyc7FGg6B7znlP1+gjlh3v8grg== Received: from DM6PR14MB4155.namprd14.prod.outlook.com (2603:10b6:5:21e::11) by SJ0PR14MB5492.namprd14.prod.outlook.com (2603:10b6:a03:428::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.15; Fri, 28 Oct 2022 13:45:06 +0000 Received: from DM6PR14MB4155.namprd14.prod.outlook.com ([fe80::2cd5:ae3c:a0cb:3f4d]) by DM6PR14MB4155.namprd14.prod.outlook.com ([fe80::2cd5:ae3c:a0cb:3f4d%7]) with mapi id 15.20.5769.015; Fri, 28 Oct 2022 13:45:06 +0000 To: "internals@lists.php.net" Thread-Topic: Proposal: Expanded iterable helper functions and aliasing iterator_to_array in `iterable\` namespace Thread-Index: AQHY6sww8NTpxZKOCkWLxQu8jgxWQg== Date: Fri, 28 Oct 2022 13:45:06 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-tmn: [GydLOiKHhS2rGqKAKFTibHzXh5oflLdkZx38Oh6GFyz9XCRARVphrg==] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR14MB4155:EE_|SJ0PR14MB5492:EE_ x-ms-office365-filtering-correlation-id: fefe5213-12ff-4135-cccb-08dab8ea9fb8 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1P7wSfN1FNciMdBtQlsUWbhs3GngT0TESq1jATN3zFh/eYLiNaVu1LC9m6csBebglvRR7nuu5a37hYJyN4MUwSe/GBtjVUg4eHGkwvvM/Md+fyNn0+0J1t5VaIW7RJdUkmbFyClg+FxavlWv+VCpPqNLZRLWQu0gGiPAqJHpasKGdZzwHwUN9sGsl2PsAIZaQXm/mc8CliGm9moEATMz0xw/IhA3mVa2Sm07/u/8AszxkWo7C2x1O1047f43lewxnU7VHPFfHmvQ0rLwsIKaJBeXugKp0qjkPLdDkn4hJQI15ZevNjBBN+q+A3aKfZd2pOz7nkimYrRMyUq7uvarNq59IcRUQiOVQqbF07YY9zOm8FBuAp80g02fUXZbDeBSzN/KGalQLIeRB/6EVSilnc6xgjU09xiQKS5ZgEBw20kgI7Nfu9AACwvv/VsDiMeKxEo6z+eVZSrI1u25+zahtesVLdWkABMDMs7SsergVeYeUNfnGVlJ7FmpzHczhype/+VVB4MkISHT7eSUFQGyIUHgCA4TJFGJjPBtu4bMc2b4djmRiU+coQScFb4HDmrkxK65q67Olnk1y/hQOQyJJ9rzqbuUcKCvgC0aph8bNU/1VX/09/N5MjmyXFGFQV8mwQjvGnP0Ny/CpcVc78XJk0APHEDCouFF+pqDCqJLQ7E= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?9nBCO/cf0GiohlEWGeYOG3k7m+1fbikkUc068521x4I82bQ8QsWcWpUT8G?= =?iso-8859-1?Q?9zoOufQhKMvMUBM7wTJLEFTSqqkg7SZ7ew1Ykn0DBJod+wxgRkPhPHVs+v?= =?iso-8859-1?Q?VoiM3G7m5UIdmpFmFxArotGBhDflF53dyqxq8+/+eK+pTGN4kBDKSIoOLx?= =?iso-8859-1?Q?re+vQv/6HHfx5p3Qx5x7CJuwFCCi/Re17sDvybRW/rWktDXEmmVVpmcdAW?= =?iso-8859-1?Q?RwdjL1814ShBZll5iapN4DcnWSVsghYziUng8Azc9OPugKNwdFRzUVmEez?= =?iso-8859-1?Q?tF3u4a2uM+6Y9wEt1RevyKVbx8yFnOVQMgGENEh9zYlpR8moBToZOzDHSq?= =?iso-8859-1?Q?PT7rLUZTQG8IpaScu2rBUNb7BwUn6KVAox47oJrZPnwb7o3uiDNFY1KJ6E?= =?iso-8859-1?Q?C2mKb06UzJgb5Af+FZ7X4iTIc8W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?3zeKwYShjRTXBICdgJBNC/kWW6gMxEWjNJTCx/YZQvUU7/o=3D?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-cd57b.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR14MB4155.namprd14.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: fefe5213-12ff-4135-cccb-08dab8ea9fb8 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Oct 2022 13:45:06.7580 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR14MB5492 Subject: Proposal: Expanded iterable helper functions and aliasing iterator_to_array in `iterable\` namespace From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= https://wiki.php.net/rfc/iterator_xyz_accept_array recently passed in php 8= .2,=0A= fixing a common inconvenience of those functions throwing a TypeError for a= rrays.=0A= =0A= However, from the `iterator_` name (https://www.php.net/manual/en/class.ite= rator.php),=0A= it's likely to become a source of confusion when writing or reviewing code = decades from now,=0A= when the name suggests it only accepts objects (Traversable Iterator/Iterat= orAggregate).=0A= =0A= I'm planning on creating an RFC adding the following functions to the `iter= able\` namespace as aliases of iterator_count/iterator_to_array.=0A= Those accept iterables (https://www.php.net/manual/en/language.types.iterab= le.php), i.e. both Traversable objects and arrays.=0A= =0A= Namespaces were chosen after feedback on my previous RFC,=0A= and I believe `iterable\` follows the guidance from https://wiki.php.net/rf= c/namespaces_in_bundled_extensions and=0A= https://wiki.php.net/rfc/namespaces_in_bundled_extensions#core_standard_spl= =0A= =0A= I plan to create an RFC with the following functionality in the iterable\ n= amespace, and wanted to see what the preference on naming was, or if there = was other feedback.=0A= (Not having enough functionality and wanting a better idea of the overall = =0A= =0A= - `iterable\count(...)` (alias of iterator_count)=0A= - `iterable\to_array(Traversable $iterator, bool $preserve_keys =3D true): = array` (alias of iterator_to_array, so that users can stop using a misleadi= ng name)=0A= =0A= - `iterable\any(iterable $input, ?callable $callback =3D null): bool` - Det= ermines whether any value of the iterable satisfies the predicate.=0A= and all() - Determines whether all values of the iterable satisfies the = predicate.=0A= =0A= This is a different namespace from https://wiki.php.net/rfc/any_all_on_it= erable=0A= - `iterable\none(iterable $input, ?callable $callback =3D null): bool`=0A= =0A= returns the opposite of any()=0A= - `iterable\find(iterable $iterable, callable $callback, mixed $default =3D= null): mixed`=0A= =0A= Returns the first value for which $callback($value) is truthy. On failur= e, returns default=0A= - `iterable\fold(iterable $iterable, callable $callback, mixed $initial): m= ixed`=0A= =0A= `fold` and requiring an initial value seems like better practice. See htt= ps://externals.io/message/112558#112834=0A= and https://stackoverflow.com/questions/25149359/difference-between-reduc= e-and-fold=0A= - `iterable\unique_values(iterable $iterable): array {}`=0A= =0A= Returns true if this iterable includes a value identical to $value (`=3D= =3D=3D`).=0A= - `iterable\includes_value(iterable $iterable, mixed $value): bool {}`=0A= Returns a list of unique values of $iterable=0A= =0A= There's other functionality that I was less certain about proposing, such a= s `iterable\keys(iterable $iterable): array`,=0A= which would work similarly to array_keys but also work on Traversables (e.g= . to be used with userland/internal collections, generators, etc.)=0A= Or functions to get the iterable\first()/last() value in an iterable. Any t= houghts on those?=0A= =0A= I also wanted to know if more verbose names such as find_value(), fold_valu= es(), any_values(), all_values() were generally preferred before proposing = this,=0A= since I only had feedback from a small number of names. My assumption was s= hort names were generally preferred when possible.=0A= =0A= See https://github.com/TysonAndre/pecl-teds/blob/main/teds.stub.php for doc= umentation of the other functions mentioned here. The functionality can be = tried out by installing https://pecl.php.net/package/teds=0A= =0A= Background=0A= -----------=0A= =0A= In February 2021, I proposed expanded iterable functionality and brought it= to a vote,=0A= https://wiki.php.net/rfc/any_all_on_iterable , where feedback was mainly ab= out being too small in scope and the choice of naming.=0A= =0A= Later, after https://externals.io/message/112558#112780 , https://wiki.php.= net/rfc/namespaces_in_bundled_extensions#proposal was created and brought t= o a vote in April 2021 that passed,=0A= offering useful recommendations on how to standardize namespaces in future = proposals of new categories of functionality=0A= (e.g. `iterable\any()` and `iterable\all()`)=0A= =0A= Any comments?=0A= =0A= Thanks,=0A= Tyson=