Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111756 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48420 invoked from network); 1 Sep 2020 00:51:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Sep 2020 00:51:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0EF9A1804D8 for ; Mon, 31 Aug 2020 16:56:24 -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=-1.9 required=5.0 tests=BAYES_00,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 NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2106.outbound.protection.outlook.com [40.92.40.106]) (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 ; Mon, 31 Aug 2020 16:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YZPKCYH+H2seuKWNcVncAAa+OhSpTn1mOqBI9Ycg2K7kazJfPz3BN/pJimQZ+NkCmNZAH7mC7Ey/S2TG6XRlGTNhhdRkrAs8mDrISwxA3zFaRL8gytYvQIPUaIL75+s+HYT5oxWSTUhFd20pH3y/yo5MwLeOKtXODOF6cyvEe6uSukQaRPIQywHlYWGxo4Og15a7bCJtg0W5h2gIRDMPdzyzf7ga+fKdmc9wcXtiXAPLV+HNijGkWHNR7M4iqFDu6HvISYdRl2X1BFYHLxg1u0DGqbbRG1DeKHvZSGyD+Tl3mBwHbuLRxNGC3Lp3cM4PtR+e56jL8sdJLCpxAF3dDw== 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=5ksNuRA8WfVVw/qlKVmHTnzD5WI4+Xdbv9E+9cJorfA=; b=c/h7amMGClw+3zllSi+CijqEC2QJl1iRlrr7fXmxz57ixNeyXqnS+Iwy40waP5lohIxeI206890ExWu+6xRH0BqVb0elS3V6ohkMUeVxZVdSF/19KpL+G6TeGpmFsIMFqJjHLKYFzQSrYJ/6Unwu1ZVXl9Vah7ueEwlYxQA3oY96x+kUw+u/wEnfLYtnzFyU8ogPRsZLSgbYE6/weB1wwcwvpgOQXj72DsDBNpOGDW88nwarw+D4lE8ZWETnkCyU5YMaFHoRab+uZYYRHjAMwK08Ug8A5rcnnny3FO6KK5GGSsK8EOd08tlFiop2lgjmZqbIJL+G9v3ePAQOzRoSWw== 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=5ksNuRA8WfVVw/qlKVmHTnzD5WI4+Xdbv9E+9cJorfA=; b=OOk4YeOynp+g7dkrnTFLSgjcjeOx2NFEmteiOIk1TV7i7bZXr2zVZEFyZ0NkeVRBARcs/FxnuuDPQnBdBqldb08aEKwgkOeb9hwGjbGKzaEZMhmuZ9bAWDooZbstt/xkfq1avLd7hcbNolIEO84GFQyvGuaAv38DZxeooKFSe2aBO1sH8ExqS4+fKq2dDs4RvVYlhsYx+ab7s01vwX70xATBL6eXtQO09Z31uu4Wy23fkspWim4ZEM/aFxEixogFPy45qV/Di6vOZeXF1IyODRnqvIDFgKsRv6VzOuYd8u81hfB2Ho2NRUkFu6umkrRZhLUTRJqYicbDOe1317EYhw== Received: from MW2NAM10FT046.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::4c) by MW2NAM10HT200.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Mon, 31 Aug 2020 23:56:21 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e87::50) by MW2NAM10FT046.mail.protection.outlook.com (2a01:111:e400:7e87::205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23 via Frontend Transport; Mon, 31 Aug 2020 23:56:21 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::f9d1:ed5b:8625:bfb4]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::f9d1:ed5b:8625:bfb4%7]) with mapi id 15.20.3326.025; Mon, 31 Aug 2020 23:56:21 +0000 To: PHP internals Thread-Topic: [RFC] Global functions any() and all() on iterables Thread-Index: AQHWf/E9QGyttklhzEGaW5Nz9+rdmg== Date: Mon, 31 Aug 2020 23:56:21 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:EE32D9FB310ABFB00F88F6324D0317E9D0019D717476E8CE9DF0D5FD920110B3;UpperCasedChecksum:822ABEECDD9ADE4CD6D6E6BCB1BCCBC7ABB05E5B72AE9E85FEC9219F66013E29;SizeAsReceived:6807;Count:41 x-tmn: [UE94QstNB0BVpQmrReSbIjYJZ2qBmrFHXp16wIrnQ2K2jwh3mpBqKS5Aa+u/A+ec] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 84db2ec2-606a-4443-0617-08d84e097609 x-ms-traffictypediagnostic: MW2NAM10HT200: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7hwERcRMTSKVTlOPAOnPv3qA+v7sdwEHlpnshpNZ49bExDLcPtO9A5X2QzJJQfOJIezzksmyAitgJWRWme3kOD2wmWeFpp3tKiFjyAhHQ6RoV6KXXW5MqxPXGVJywpC/ilQgSihkN7nWCkL0S0Ze6MOpHAn3v6oqGSf7H4jGWdZG/nIoxkYrP5NVJ8Ddl9h6qpFtyt6KMHVTCxbeSDwF/lksTJplez9EERF3z9nrPlWFfR5fiiPTNdhXxQfyvFfc x-ms-exchange-antispam-messagedata: YilmJsxzGsXtx0Yk/pPrnD47iCL5pNA7KI4ve74hounxOj7NUzuKBKb0sH0o2gvgzxTzNsm2cbVCrKdbytvv7VJNmROACDFaw3GOWrfhALnWiRH1vgzxx1uD+P4DAIMr+BSz1J5W0xVgqptBMDPoyjIwHB8mKzn/1bm+Wr5fgQzEwXD7SgeBqAFHMnW5EtgLjwvKmuB3+rhvDzxLsx/gTQ== 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: MW2NAM10FT046.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 84db2ec2-606a-4443-0617-08d84e097609 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Aug 2020 23:56:21.4560 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM10HT200 Subject: [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 so= me interest=0A= ("Proposal: Adding functions any(iterable $input, ?callable $cb =3D null, i= nt $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 langua= ges and help in avoiding verbosity or unnecessary abstractions.=0A= =0A= -=A0https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v:a= ny=0A= -=A0https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Globa= l_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.html#= allMatch-java.util.function.Predicate-=0A= =0A= For example, the following code could be shortened significantly=0A= =0A= ```=0A= // Old version=0A= $satisifes_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 libr= ary.=0A= Using array_filter would unnecessarily call satisfiesCondition even after t= he 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= Thanks,=0A= - Tyson=