Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111711 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4209 invoked from network); 29 Aug 2020 21:20:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Aug 2020 21:20:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 742631804D9 for ; Sat, 29 Aug 2020 13:24:48 -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 NAM04-CO1-obe.outbound.protection.outlook.com (mail-oln040092010105.outbound.protection.outlook.com [40.92.10.105]) (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, 29 Aug 2020 13:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=htqgQmrl5TmVvefiygLsrD8LkqYjIHub8qnBFPN+RMEp8On3WVvOg57y+rx32yj8GNHVMl3Ri4Ub2eJcR1NGFQHPZj2NSkgD3Mf/xKPey49f2f+8YcomIVifZE/NctcMnS3rugJYaOeX+l8fneepiGKYZJIO5Bk/sGKfn3PoC0uhqVCrY7cVESRnbLRy/JFWpYZ/laiR5LAmEUtV8YMb23YjV7kMjpeIwECi6nyv7q/hjEmHkVwWiazgg54WEboo/UXGJkUudamjh58yaA21rtAo2Os4Mcd3zDUROUeMVB9JqA7hQQ0Vv3eAbtmZj69VMU3YmPi9QsO9Mmzft3U07w== 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=VJleqguiGcJz7NH09UOS/BP2GbztNYGIdaMIq7lP27Q=; b=oCF4g9ibyxCgAhCHDUHPMYtwcuZ9z0SlBTbBYmWMp1ghI9iS0hAFG8Neqfi+8zCjs5HLZZx0/V5ESHVoAKwyRZHPOP8wWukqqeVEklnr+azte2har7B47RLwsWwFh8zFo+fVza32QsS0pEVMI0vQx5kEiLlzztGW0Ir3avIgixFERvWPe9klMGabigwaY2GsWtbIDvmKI/ZQs7NcKGA/20FtrXBdfY9Tgfdf4C+wK6fExROfTYlyI3uPYjd/j1UMj3kNj46eMFTbtjwXtm2WCMX4sVbSRVi6aR0jM9L0Q8okL32hDIki0igB6yAHoEmHDWuIWkJ43rBqyTdU0RJYRA== 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=VJleqguiGcJz7NH09UOS/BP2GbztNYGIdaMIq7lP27Q=; b=ad32K1N6c0I+NZaPk/jFuriS0+LciL7NhiH1q6sbc+ZX2YDC4N3u3wn+6Lo+zOQZWRQB0qP3qqOnun4fBLqwJs06fPO73X7JvJ588snHFRzZ348v2vDyXkkPHP6/DPDF5y3VRdi/ZruZKTveWWc/vfhlpNrQGyQdwOr3sXq7Y42kucCYpmJZ/zQk6HJHB2v1n1AnpAAbjeSXxsxJ8wz0OtsM8iECukyAE6IsAlVEmyk3EvCBaoPwEuFTd3Q6WBEd7XCPkRfXg2wF7SL0jX6wXR/BwPQRA/4AY4nOAZjCCxVR26GC9C+OpDZySdSArQAAFiHbSCsysMkr2aqL6q4jrw== Received: from CO1NAM04FT024.eop-NAM04.prod.protection.outlook.com (10.152.90.55) by CO1NAM04HT114.eop-NAM04.prod.protection.outlook.com (10.152.91.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.21; Sat, 29 Aug 2020 20:24:45 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e4d::42) by CO1NAM04FT024.mail.protection.outlook.com (2a01:111:e400:7e4d::105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Sat, 29 Aug 2020 20:24:45 +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.023; Sat, 29 Aug 2020 20:24:45 +0000 To: PHP internals Thread-Topic: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) Thread-Index: AQHWfj2/bRooGr39CkeRSgZBGY4s+Q== Date: Sat, 29 Aug 2020 20:24:45 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:88B7E47DA0CCD8351E94929647A0AA1C90347DCA5E12EBFA9D5013FC4E103DDF;UpperCasedChecksum:09B62415268985839C027BC9B2A27ECEC07417808B23416741609670E62C266F;SizeAsReceived:6912;Count:41 x-tmn: [+PNClruGTh+XCFOhENTnwYtg8GgldtXIaGgVOKrB0sFLFs5iDXBH6nYJeeMxwLJ2] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: ebcd9d57-4cbd-480c-2911-08d84c5991f4 x-ms-traffictypediagnostic: CO1NAM04HT114: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +u0B0aTek11GWZLx3H0h4h/zK61ct9vY84I9BAAqncrvwIXFTWIh+Kwaw1cPgRWzJ2VzIfHcga6QqIlnJnHASlMjiulgFcbKArJRQBve/ppd/TDe44Q+mJkf6KtEmX5/MyJjsJUTWVobdXMO0BKoR+RxQaraxVbf6Nxryhtg6qJVwRlq5Hlda9zdIvyrzwK8zZ7rUujKXDmbH0BiRoKpffequCUw6XFwEHHD6OTgW3ezxc6UjK7GOxSQuv6gpLQC x-ms-exchange-antispam-messagedata: hlL8YfncWI5W6H/ZE4MT2KiZArJfyaE6Fd25RDNZsJUg7L8UG1vCdybrYWKiPF1+u8CPZ3AaptDlnHwmtChJR8ciGaf5UWUdQrcel1wNih/FI7ExAcIgcYq6khICPx4tbV14QOdPqtP5tayWFzmDRO8zuJqSuJHF8VPWWBiXVLfMFJVD6kJ3n6uPvazVbP2rStNMucr+M32JKpnE4f2wyA== 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: CO1NAM04FT024.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ebcd9d57-4cbd-480c-2911-08d84c5991f4 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2020 20:24:45.7073 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1NAM04HT114 Subject: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: tysonandre775@hotmail.com (tyson andre) Hi internals,=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= - https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v:any= =0A= - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_= Objects/Array/some=0A= - https://docs.python.org/3/library/functions.html#all=0A= - https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#al= lMatch-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 ($items as $item) {=0A= if (API::satisfiesCondition($item)) {=0A= $satisfies_predicate =3D true;=0A= break;=0A= }=0A= }=0A= if (!$satisfies_predicate) {=0A= throw new APIException("No matches found");=0A= }=0A= =0A= // New version is much shorter and readable=0A= if (!any($items, fn($x) =3D> API::satisfiesCondition($x))) {=0A= 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 https://github.com/php/php-src/pull/6053 - it = takes similar flags and param orders to array_filter().=0A= =0A= Previous discussion was in https://externals.io/message/103357#103373=0A= =0A= - New contributors to projects wouldn't know about any() and all() if it wa= s reimplemented with different semantics and only occasionally used=0A= (e.g. MyArrayUtil::any()) in various projects)=0A= - If this was provided only in userland, there'd be low adoption and code s= uch as the first example would remain common.=0A= If the standard library provided it, then polyfills would as well, makin= g cleaner code easier to write.=0A= =0A= Thanks,=0A= - Tyson=