Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111717 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41968 invoked from network); 30 Aug 2020 07:27:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 07:27:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E55B180531 for ; Sat, 29 Aug 2020 23:31:39 -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,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 29 Aug 2020 23:31:38 -0700 (PDT) Received: by mail-qt1-f171.google.com with SMTP id b3so2613342qtg.13 for ; Sat, 29 Aug 2020 23:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=x5UsWW7g9ZpgjLikdFEV5C5TGpLlRjvBXZZVPPmQ4GA=; b=W0Uw3HCpgKSOjPBWhD0uArC4a4hxSdxOyGUVmzIduHsqno65P0S7yIBpxHFpugXdSu Sxy6aWpaJL80T1UqHz5+2tHm1rKLlBlgYZIAvL62lnVQzXByLGWQNeZSZJ5j7kc2X23B IcZ3DclZSu6UsrHDtjw+ZvO9EuYJq/wQr0R0wiHMUIyXPKnJ6RBiLorprAnajmrOtF+o VIuBd2D/oA6qi3QhD5f9MsbWLw2qb2/QqOyneTkXZWJdBuqp2Rqm4YOKVKBmkbO0LTb5 q0KbpwvdOzYX94CnRrgTaWl2RDhlPJ4ViM0okYIoUhanfyX+fidVXy4lTqf6YYTHPgI3 be/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=x5UsWW7g9ZpgjLikdFEV5C5TGpLlRjvBXZZVPPmQ4GA=; b=d4s94kWMaugxBVDvL6g5AeWPp5P1CNVhdkYTXOOp1v5KifAQHv/0nCM0qnbP55SLHf lek2FKW56tzNQAtoCFbpUyxnIgKnyZVNNRIkVou34fXRQtPKU2apdMDAHsvK67kKjH5n cGM6XwHBhJ7iyB1IwUmQgqmaKbw2rM0NRhBvKxE215MnW05jA3damxvdrQJ81U/i524z zYtSu6CougTGNtjtkaRqZZqhgK55Wh/UC5pqVZnyYY7wNH4UZrJNSMAqxM2oRtkBCX3H 8/YxL9zfuznrPVTjJI59PCJbyc3p0FgjlgK0tFgmXok2NFiWtS5I/5ccMCmiMOvvXRuu XtRw== X-Gm-Message-State: AOAM532MYZgvBLbBl7Gjzv9ZNFv44y53+7m354xwNnmV5MSEYRRn0trg jC6l++M9Uwi7Fmm155i2LOLdcg== X-Google-Smtp-Source: ABdhPJx6VCYuTqTYTxmsbKe64vU1uubv0DGH9QHVA1hL1mH+BvMbsUcRuugnC1t82Wofs6FJJxT+Vg== X-Received: by 2002:ac8:1c3:: with SMTP id b3mr8380322qtg.240.1598769097073; Sat, 29 Aug 2020 23:31:37 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:edc5:8f00:3101:2cb3? ([2601:c0:c680:5cc0:edc5:8f00:3101:2cb3]) by smtp.gmail.com with ESMTPSA id q58sm5622370qtc.40.2020.08.29.23.31.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Aug 2020 23:31:36 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_82AB31E8-4B5A-41AF-B532-1A09F96C96F0" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Date: Sun, 30 Aug 2020 02:31:35 -0400 In-Reply-To: Cc: PHP internals To: tyson andre References: X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_82AB31E8-4B5A-41AF-B532-1A09F96C96F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 29, 2020, at 7:18 PM, tyson andre = wrote: >=20 > Hi Alex, >=20 >> I like it!=20 >>=20 >> What is the $use_flags parameter for? >=20 > It's for deciding what parameters to pass to callback, like = https://www.php.net/array_filter - the reflection name should probably = just be $flag >=20 > Occasionally, the key might be useful to check against, e.g. the = identifier of an item in a map, or SplObjectStorage. >=20 > - the default is `any($iterable, fn ($value) =3D> ...)` > - or `any($iterable, fn ($key) =3D> expr, ARRAY_FILTER_USE_KEY)` > - or `any($iterable, fn ($value, $key) =3D> expr, = ARRAY_FILTER_USE_BOTH)` Doesn't the occasional required use of long constant names like = ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH somewhat negative the = benefit of a more concise syntax? =20 I know that many existing functions in PHP have a collection of long = constant names that can be passed, but is that a style of programming = that PHP really wants to continue to proliferate, or would it not be = better to address that use-case in a different manner? (Admittedly = doing so might require having this feature dependent on other critical = path language features.) One approach might be if PHP could allow for skipped parameters in = callables =E2=80=94 where I am using a single underscore to indicate an = unused parameter (GoLang has a "blank identifier" for similar purposes = so there is some prior art to consider) =E2=80=94 e.g: - the default is `any($iterable, fn ( $value ) =3D> ...)` - or `any($iterable, fn ( _, $key ) =3D> expr )` - or `any($iterable, fn ( $value, $key ) =3D> expr )` PHP could handle it more generically, is possible, or recognize this and = branch to different implementations of any() and all() if the goal is to = optimize performance by only passing one value in key-only or value-only = calls. Optionally we could use null instead: - the default is `any($iterable, fn ($value) =3D> ...)` - or `any($iterable, fn (null, $key) =3D> expr )` - or `any($iterable, fn ($value, $key) =3D> expr )` -Mike [1] = https://www.geeksforgeeks.org/what-is-blank-identifierunderscore-in-golang= /#:~:text=3D_(underscore)%20in%20Golang%20is,Blank%20Identifier. = = --Apple-Mail=_82AB31E8-4B5A-41AF-B532-1A09F96C96F0--