Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111723 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73303 invoked from network); 30 Aug 2020 16:08:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 16:08:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 009F4180532 for ; Sun, 30 Aug 2020 08:12:55 -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 NAM02-BL2-obe.outbound.protection.outlook.com (mail-oln040092003057.outbound.protection.outlook.com [40.92.3.57]) (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 ; Sun, 30 Aug 2020 08:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KPdBSmdikTUpahFjPe1TOIecBzD46Lc2M6z6s5MoEM/g7QNjXsVBCzk8I0+65DLMuqiZRsfW1IeBzbeufvSQAxNsqutW4lFHn9IeCSh/EueW8rNDv8KDz9Kg4bksbfB+cyAEApYzb5NU/nNxZ1FWPS6NCIKxJUnZ/+gWoKll02E3qV3PxMO/ffNNgXBVLpMBCgsIlGzPONO80H5tKRC8QgvJs+8wg341eni2t+ZGJnIHrKKcSuGGeh7TTmIdj//wGulJ5rMfX5H1/R+8XefmZgjEYdREOXMW5oMRIVqv/HT9cJMLP+yU1oZRWwFbpTTgJ+OWxXqbZeo2v5He1001iQ== 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=H3dShMk6F/qhXL20ruX2XE6XgkeWj5BnNbOppMeoKl8=; b=bKUJEVj0Mx2Ny+WIChciY5nP52WWQQ+cuUAm24VIad/zme81H9oueXacfOhc41LY/OdmRYRIJAyQV67Vn54ZhXd/C4yLWrznsNBFWucsXq/SrJp1VJ4utfsXUSAuEOLyTAdcBvjIsuGbNK0FrIZpBAPgImhHnMoz6fSxlXPzja9uWb6215GTAZZ/doymgUNDqicQzTTueofFFyQ/EgcMj2yFCC6Eqesvd8CdF3Cf2XBCtB63ln88C6fIWyBvKispQhD5ozY4q/mn89ufYHQ91c5/WsQZiGtlPfZFNX3volD6qXLo4qapAzxq9cs++BypXq0vhQT8CeIhj74vOGdJDw== 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=H3dShMk6F/qhXL20ruX2XE6XgkeWj5BnNbOppMeoKl8=; b=LrB1EJB7KaWB9R3bk16xf2hPh7Fynb4fpdY7Dc/FsAKuLXl4s0ejdVD1mpGMTNiGq8X2+RuECu0+geV5fkYlbvhGdHanVsKxJAmQHfD/6rrUB5C5/1hM73fFp+2bRhhq/+bb63cYLKPlCYI9Bal22iSgUTryvhY4mAy+H+KUpFqAkWCCk52U+dBnjzmnFwNQnFP3ntNR4E6FxQbdqcYToJh+61orB4Sw4XUJ5T1YPc8HtncEyX01R83DxBa1ar4JsUJT2wN3oUPWj2YFoODK7IG+SwQwNX+nWXbQZc9LkmID4KL/hG1TL4Hwt1dxmo9N1SUryKp1ZOWfRYCnm8FZlQ== Received: from BL2NAM02FT017.eop-nam02.prod.protection.outlook.com (10.152.76.56) by BL2NAM02HT113.eop-nam02.prod.protection.outlook.com (10.152.76.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.21; Sun, 30 Aug 2020 15:12:53 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e46::4e) by BL2NAM02FT017.mail.protection.outlook.com (2a01:111:e400:7e46::430) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Sun, 30 Aug 2020 15:12:53 +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; Sun, 30 Aug 2020 15:12:53 +0000 To: Larry Garfield , PHP internals Thread-Topic: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) Thread-Index: AQHWfj2/bRooGr39CkeRSgZBGY4s+alQvQSAgAAChTs= Date: Sun, 30 Aug 2020 15:12:53 +0000 Message-ID: References: ,<7d91bd8f-9ca0-4e62-886b-f89bc8edd3e9@www.fastmail.com> In-Reply-To: <7d91bd8f-9ca0-4e62-886b-f89bc8edd3e9@www.fastmail.com> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:ECEFE9E7CFE1BFF7C9EBD3CEA49FEB7D892282FB6A2FFD7BB48901CFBC23CAAC;UpperCasedChecksum:6D2BDBFBAFF729FB0D5E14181205065570B6F3F8F63F185CE239DC4071ED9BA2;SizeAsReceived:7285;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [n9K7zYyebQughjDsYW5sxEU5oZYBByGoALFTuviyJJ6beYG36eGu01TXjBjl40PK] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 7cc6f79f-7d52-420b-d686-08d84cf72ac8 x-ms-traffictypediagnostic: BL2NAM02HT113: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yyldX/gO2rmGC/6UY3cNNO4hsjChCdb/WWb2QAGBYFA1bqmr+HGl9uAq/ttw5i1Yp5WHekDBhvSapZeHu5VIZHDu3pYNvZJr1bbimlHycW3MdzDnnApb3eGXssRMv4UciO1SBGmTAh0Mrz37fjM/nez3E1yhOeNJMdydZVvrRg9yfXaaAfR8mrCSuw6rQe/ubxtBBekZnHagITE4pndPsQ== x-ms-exchange-antispam-messagedata: WSljYOYYDGTwEZo/2xOz1zm71+r+jnxNMcUDp0X2A+4J8FEQWIUB7xow+8tJzKvmBCBE609MBASmEORaReqDOrji/dg5+1mFXyzNChnuPsyBcrckhgyGtKEqQ2aZmVArh3wCbHAMEBqTrEU+mvNbcfxbkPlzEvED5FK1eaTaOsrgGNiVdiPELlgiUSAGDjg++zC7rALrQrJ9wNI/3bQzqA== 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: BL2NAM02FT017.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 7cc6f79f-7d52-420b-d686-08d84cf72ac8 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Aug 2020 15:12:53.0523 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2NAM02HT113 Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: tysonandre775@hotmail.com (tyson andre) > I like this, but I do not like the flags.=A0 I don't think they're at all= useful.=A0 A lot of the other discussion in the thread seems to be needles= sly complicating it, too.=0A= >=A0=0A= > all() and any() only need return booleans.=A0 Their callbacks only need r= eturn booleans.=A0 That's the point.=A0 first() makes sense to add, and it = would return the first value that matches.=0A= =0A= What would first() return on failure? Would it throw (inefficient)?=0A= Would it set an optional output reference to distinguish between returning = the value null from an iterable and the null from no matches?=0A= =0A= An alternative use for a global function called first() would be to simply = return the first element of an iterable, similar to the proposed array_valu= e_first for arrays=0A= =0A= > For the callback itself, there is work to, hopefully, add partial functio= n application to 8.1.=A0 (No idea if it will be successful, but the effort = is in progress.)=A0 If so, the upshot is that turning an arbitrary function= into a single-parameter function becomes silly easy, which means functions= like this can just expect a single parameter callback and be done with it.= =A0 No need for extra-args or flags or whatnot.=0A= =0A= > If you want to check the keys of an array, call array_keys() first and us= e that.=0A= > =0A= > `if (any(array_keys($foo), fn($k) =3D> $k %2)) { ... }`=0A= =0A= That doesn't work for a predicate on the keys of a generator, e.g. if you w= ant to stop calling the generator once the short-circuiting happens.=0A= And there are occasionally situations where the predicate depends both on t= he key and the value=0A= =0A= `any($itemMap, fn($enabled, $itemId) =3D> $enabled && meetsAdditionalCondit= ion($itemId), ARRAY_FILTER_USE_BOTH)`=0A= =0A= Still, since there's debate over whether to even complicate this by filteri= ng by key,=0A= and what the best way is to implement filtering by key, I'll probably take = out the `int $flag =3D 0` part from the initial RFC.=0A= Those can be added in subsequent RFCs.=0A= =0A= Thanks,=0A= - Tyson=