Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111775 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86437 invoked from network); 2 Sep 2020 04:29:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2020 04:29:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8FF64180502 for ; Tue, 1 Sep 2020 20:34:17 -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-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.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 ; Tue, 1 Sep 2020 20:34:17 -0700 (PDT) Received: by mail-qk1-f171.google.com with SMTP id f2so3153398qkh.3 for ; Tue, 01 Sep 2020 20:34:17 -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=04vQI15ZXHKQ90iSI94eiM610rVkJ7ZbJoaAN+4Ss68=; b=FA6kXrkZG2LNfjJYS/OEA3l7Pl2f4ervD4RFgqAphnlK00in0Eq6k6pMZwAZBJQYLS GTRgigWbm60CgsztwjinK5KJCZ7YoeyhU084TGAc9vwUTsp4JyQRJkOug4Q4DHAsl63p AXMc5hX4wxgJtG0ui9kb+TjQfqtXZKMzM+dp++2SHWYD7Tvxwt15W/42eLa7V5CcUYl2 ZAazZCLxArOAAofVaeST80BDPrYV7uc/wYOa+twV8e/uSR1kOpRfAoZAEIt39w6Z1pq3 OBOPOyWYTsAaaafvZgm3kHXrK7tsWiCaEqPRZ0s2D2TlfFUhuEr84sZdTvyjI/2OIxbf P7kg== 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=04vQI15ZXHKQ90iSI94eiM610rVkJ7ZbJoaAN+4Ss68=; b=uoKQHX+qfPQru1xgilRKhFqe9NnAG+JYW4W59nKgzANKx3Y6ORWQvbIU2rk4tZ9yTp ozXk3/KZ/g2c8AxLH2vMO+EngVrsQDeF1eY8BpZz/wRjgEnst1Ohsrr1EoqJMuvvCa97 V28OJVf+EjxuDtgCmOjICXF0EEhZYsyPlcNOHS1vfZK0sqVMRLaRhWoQWs6odNYxIzLg u4B2hPv/emWeg5f714LkmtG7QC1oez/Rt3yuWvODnS23t0aKFY5PxVPePOnlay56qvOb xoz82vNo7qPWAr+eUNp5CLRCYHxmqNC+yHALnD5/mtDvuzcuw6Kh2dRyqWDB6twKbu4a 59QQ== X-Gm-Message-State: AOAM532F83jIiNwAH3imuKdZAW38x/kNmuWNYbbhczeURwYgCKvtAPtR 69DGbTqyFeDlmZn6Ey9T9jC9vQ== X-Google-Smtp-Source: ABdhPJzw6aC7i5r053w8xVaZQnmtl5PIpLbPhGbjomm5caA24LlZwfpohP0ZZ7ZU7w54sxWSBX51EQ== X-Received: by 2002:a05:620a:a05:: with SMTP id i5mr5206646qka.102.1599017654689; Tue, 01 Sep 2020 20:34:14 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:6572:ebee:6047:150d? ([2601:c0:c680:5cc0:6572:ebee:6047:150d]) by smtp.gmail.com with ESMTPSA id p205sm3898506qke.2.2020.09.01.20.34.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2020 20:34:14 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_03F2C304-6309-482F-A3B6-EC50CAFF09FF" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Date: Tue, 1 Sep 2020 23:34:13 -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=_03F2C304-6309-482F-A3B6-EC50CAFF09FF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 30, 2020, at 12:31 PM, tyson andre = wrote: >=20 > Hi Mike Schinkel, >=20 >> 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 >>=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.) >>=20 >> 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: >>=20 >> - the default is `any($iterable, fn ( $value ) =3D> ...)` >> - or `any($iterable, fn ( _, $key ) =3D> expr )` >> - or `any($iterable, fn ( $value, $key ) =3D> expr )` >>=20 >> 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. >>=20 >> Optionally we could use null instead: >>=20 >> - the default is `any($iterable, fn ($value) =3D> ...)` >> - or `any($iterable, fn (null, $key) =3D> expr )` >> - or `any($iterable, fn ($value, $key) =3D> expr )` >=20 > Supporting "blank identifiers" is out of the scope of this RFC, > and would have some implementation concerns of how it'd work with = named parameters > and how backtrace generation would be affected. I don't think there'd = be a significant performance improvement over not using parameters. >=20 > I'm taking $flag out of the rfc because there's many proposed = alternatives for doing this, > and checking values of an iterable is the most common use case. Acknowledged. If not a significant performance improvement why not pass both value and = key to the callable in your RFC in case someone needs access to the key? = =20 Adding the key as a second parameter would not preclude passing a flag = to modify behavior in a future version of PHP if that is the internals = consensus. -Mike P.S. John Bafford recently suggested the use of void in foreach loops = for essentially the same reason as I proposed with underscore or null = (and frankly void is better than underscore or null):=20 https://externals.io/message/111774 = If his RFC were to pass then that would open the door to using it here, = right? --Apple-Mail=_03F2C304-6309-482F-A3B6-EC50CAFF09FF--