Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113102 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58519 invoked from network); 6 Feb 2021 15:16:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2021 15:16:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2E76B1804E4 for ; Sat, 6 Feb 2021 07:00:45 -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=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2089.outbound.protection.outlook.com [40.92.22.89]) (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 ; Sat, 6 Feb 2021 07:00:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1Ib/s3f4kMRvilBA+WcHznnWqBrr2bRbW0ALIJdJlyrGzO+uvK616GmR1fXI3q/6rL+EkDZ4dXMnIw/mgWS1xz8Wf2YOoHy7kxSgGhmZIDyT+1ALWh+kD1Ecxd1KhlLBQiwU4gNCmfUV1/wMDudjp5tnYhxymekxHRhvq1wITURWvj5XaPYI0H71XEEwgbEFcnuslrFjfJeIhP2Wp094RUXmDiPssL8boDzWRChkV4/ENLZdqmVbSB3HUoIoCrtLiB0GFq3McqdCDjxcr7rWHLDs5tBpjVIteI9TzCK/xkieUkTb843eBrVbMNRs6zrMQbs11gl3pjcCnqoPz9jzw== 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-SenderADCheck; bh=EuLXOhvmw/7rXdqHw3iH7+8pB76DcsNHp+PgCt9tbFQ=; b=JNPL/QGxnvRLorl/ZpG+o7ga0UzqAO/GcYLbWIfVVR0pH57FJ4b3JiPtl3bUMzz/ujtUYCeTRuWfl68qyvEI6Qf9iXsqcxzhy3fpN0ejGxvl6rxt1d5JBl4Fpn752m5SLT45O6ei80luIr6sxDAsRq7ikWb8Q6oLVYDuwrSwUcyw/tWfRFzLSde1O4Mgteq9kbN3Kl8IgdugUIlNovwS1AC9YkhHGPU7wpxPh5MaY5zjNS1aUcfYyIvZZ8SAoRK5V4En8HVQwtaxmGAe/fJKP/3j30gKS6NEtAVW8+mFv65JcKR7KgfI7+cQwjOKDHKXOGuWRppfWC1YOB2lqKLSmw== 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=EuLXOhvmw/7rXdqHw3iH7+8pB76DcsNHp+PgCt9tbFQ=; b=qT6yUwTp6BRx+XS+Wzt1Kg1HOzcs5U65ccM9LQSpY/heufdpDSqODNMGNNkiPUKEOjpYsznbe3gkO39gqEuL7M5ugEt0BkI6ANfLqE87nvwFGT8ZAAaFtfUZKMbZpkaICgd8tlQF5cr8MuZlLo71hKYPmXWKTj1n8PhWuNm528NEIypmvNPNEhHzJYicfIf6KHHPpUhNIihdZT4piD2ckUtswoSNWdWf8fCBIKm5tVQlm5HV+ZQ+RXoa5bKuldrLb7Hdu74/Sls19yjeof4jJsTw9i1MnTu4nefgLUVOfTcoeuxGHhPvzhPPetsuQp0l0h0+bLXCV+SFHSBOImf1iw== Received: from DM6NAM12FT018.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::48) by DM6NAM12HT236.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::291) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.11; Sat, 6 Feb 2021 15:00:43 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc64::46) by DM6NAM12FT018.mail.protection.outlook.com (2a01:111:e400:fc64::474) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.6 via Frontend Transport; Sat, 6 Feb 2021 15:00:43 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3805.035; Sat, 6 Feb 2021 15:00:43 +0000 To: PHP internals Thread-Topic: [RFC] Global functions any() and all() on iterables Thread-Index: AQHWf/E9QGyttklhzEGaW5Nz9+rdmqpMLR4Y Date: Sat, 6 Feb 2021 15:00:43 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:37E346B54E6BF6882C326098C73B8BC2431644C30418EF06D8EDB7FE2CBA0E0C;UpperCasedChecksum:27C9301E3A58501DDC6AFEBCDED51C1374657503462082AFED97B3A79103BB28;SizeAsReceived:7038;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [GbMQN9+T+dPcKyXFSVzaXs5lzBM/CwcISA0sLzgkJHrBaxBgm8e46VZqoDkRRwYW] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: f74e45b6-74cc-4093-7c26-08d8caaff9fd x-ms-traffictypediagnostic: DM6NAM12HT236: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ITWlS5TPmzUgr/viTYzeA7R2UxR9FghjQEClXA+K734iJmy3so5OsG/XYKG3ZZsq7MJgCW6ah/XKk4vP5lNdDtKpsTGhrJ0hYcvRkQsTsoy26/royyuNbbRq6ZJt4ugKT4AW8Q/DE/IAs/ioi3i69s4pZLW0lSGwm+OJp2+BwPY9+jsSeUSA1ypQn77jmraUJQ7PpXjxv0BmJndHQ9Ga5koNPGRWoJ9viwHmg8FISYVNqDoUIy4gjewiyuu31VgVtmzQxGIQdZK0Xlwydw+T2fuPCBICoNOodZKpCYdboWmSSzjZsxYGpnRHFhAjK3zNT3S+2ai8dw6KIz+n+myzpmQv7J6pxgqmE3Y7t7uHluBAm0dMBetjPZr6mZdHeH9WvAPUctnZui+PRQRgvMqPBk2LOphDkEKSmkZIEbHQylQ= x-ms-exchange-antispam-messagedata: I9dwG6HiRTV3Ff5SV1KzUWG2wRYNkxxjoOIl0iwdtf+QGB/QBHwl+OnHBOAC+CehvVwTC0tewoou+orj2BqPzC6NUd+mdyakgoQhNg4iSgnu+46bdZPyWHBE6hyhy4ymKwPQNVyn5VQoslu4cuMEzEO0TW2iOJ+YZI4e/A3QhN2038D9htYRnnmX+d2Uqs+9yEmC7Wb/kmaKFym5hUxQqg== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM12FT018.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: f74e45b6-74cc-4093-7c26-08d8caaff9fd X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2021 15:00:43.4652 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet 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: DM6NAM12HT236 Subject: Re: [RFC] Global functions any() and all() on iterables From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= > I've created an RFC for https://wiki.php.net/rfc/any_all_on_iterable=0A= > =0A= > This was proposed 2 days ago in https://externals.io/message/111711 with = some interest=0A= > ("Proposal: Adding functions any(iterable $input, ?callable $cb =3D null,= int $use_flags=3D0) and all(...)")=0A= >=0A= > - The $use_flags parameter was removed=0A= >=0A= > The primitives any() and all() are a common part of many programming lang= uages and help in avoiding verbosity or unnecessary abstractions.=0A= >=0A= > -=A0https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v= :any=0A= > -=A0https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo= bal_Objects/Array/some=0A= > -=A0https://docs.python.org/3/library/functions.html#all=0A= > -=A0https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.htm= l#allMatch-java.util.function.Predicate-=0A= > =0A= > For example, the following code could be shortened significantly=0A= > =0A= > ```=0A= > // Old version=0A= > $satisifies_predicate =3D false;=0A= > foreach ($item_list as $item) {=0A= > =A0=A0=A0 if (API::satisfiesCondition($item)) {=0A= > =A0=A0=A0=A0=A0=A0=A0 $satisfies_predicate =3D true;=0A= > =A0=A0=A0=A0=A0=A0=A0 break;=0A= > =A0=A0=A0 }=0A= > }=0A= > if (!$satisfies_predicate) {=0A= > =A0=A0=A0 throw new APIException("No matches found");=0A= > }=0A= > =0A= > // New version is much shorter and readable=0A= > if (!any($item_list, fn($item) =3D> API::satisfiesCondition($item))) {=0A= > =A0=A0=A0 throw new APIException("No matches found");=0A= > }=0A= > ```=0A= > =0A= > That example doesn't have any suitable helpers already in the standard li= brary.=0A= > Using array_filter would unnecessarily call satisfiesCondition even after= the first item was found,=0A= > and array_search doesn't take a callback.=0A= > =0A= > A proposed implementation is=A0https://github.com/php/php-src/pull/6053= =A0- it takes similar flags and param orders to array_filter().=0A= =0A= The implementation and RFC https://wiki.php.net/rfc/any_all_on_iterable hav= e been updated =0A= after finishing the previous straw poll: https://wiki.php.net/rfc/any_all_o= n_iterable_straw_poll_namespace=0A= =0A= This is now a vote on `PHP\iterable\any(iterable $input, ?callable $callbac= k =3D null)` and `PHP\iterable\all(...)`.=0A= =0A= A secondary vote was added for choosing between `any`/`all` and `any_value`= /`all_values` within `PHP\iterable`.=0A= =0A= I plan to start the vote on Monday.=0A= =0A= Any other feedback?=0A= =0A= Thanks,=0A= - Tyson=0A=