Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112574 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93395 invoked from network); 21 Dec 2020 16:24:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2020 16:24:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CB6401804E4 for ; Mon, 21 Dec 2020 07:57:11 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (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, 21 Dec 2020 07:57:11 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C3415A9C for ; Mon, 21 Dec 2020 10:57:09 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Mon, 21 Dec 2020 10:57:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Grzt5V GU6T2LHHN4XUQzDhSSqrIK5Enur9vbHD3o5hI=; b=GqHY/F4S3/A6AaGl+5gsoH m3YTcJU2KVjJrZHMXrCDBfL5+UvEVBAPSCamli125rb8IGIQt2HzWnXwtBJZT7Uk 3MNyUTt/ue6XckRrLgeV3/Jix4TrUO8d+BekJipJlk8cyJPxmDoZq6wjTpV7DXPy +Sv4WP1ZKulzwFUAFREcBmi1/7Px5gLQ3A5AcvlTzmk4T8GohDXSptSY7YdxWzL9 1yc60k3vnHRdbrU2dPUK7xOizLEcsIP6lFuLrFP64tmj+EFI06ywcKHndkQ4lfuq vCodTUM4wMjchPOgpN28BYJ22BkVYJNKXj8rj1/jQpAx96ahRfdlFcVB2JrwHC3w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddtvddgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeejteehieekteevteefieefgeeuiefggeevvedvffeh fffhgeektdeljefghfeukeenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhorhgrtg hlvgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id B17AE14200A2; Mon, 21 Dec 2020 10:57:08 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: <46be5a21-6fcd-469e-a214-09864ffaff23@www.fastmail.com> In-Reply-To: References: Date: Mon, 21 Dec 2020 09:56:48 -0600 To: "php internals" Content-Type: text/plain Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Re:_Straw_poll:_Naming_for_`*any()`_and_`*all()`?= =?UTF-8?Q?_on_iterables?= From: larry@garfieldtech.com ("Larry Garfield") On Sun, Dec 20, 2020, at 5:56 PM, tyson andre wrote: > Hi Mark Randall, > > > These functions make sense. However I think we need to give renewed > > consideration to: > > > > $itr->all(); > > $itr->some(...); > > That wouldn't help for arrays, which would be the most common use case > - I don't remember seeing an RFC for > https://github.com/nikic/scalar_objects and that is a much larger > language change. > > This also wouldn't help if I wanted something that could be used on any > Traversable. > Currently, there's no support for default methods for interfaces such > as Iterator/IteratorAggregate - I think I saw some discussion of that. > (e.g. to check for any()/all() on generators, user-defined classes, etc) > Backwards compatibility of method signatures with the same names that > were written before default methods were added would be a concern, > though. > (https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html) Related: I am planning to get back to the pipe operator at some point during the 8.1 cycle; right now the only blocker is finishing the partial function application RFC (which is partially completed, no pun intended, but currently lagging due to lack of time; Ilija was working on it but is focused on enums at the moment). Assuming pipe passes (since the feedback was quite positive last time with the caveat of wanting partials first), that would open up the potential for functions that return iterator-expecting functions to be used in pipes. To wit: function i_map(callable $fn): callable { return function (iterable $list) use ($fn) { foreach ($list as $k => $v) { yield $fn($v, $k); } } } $any_iterable |> i_map($some_callable) |> i_filter($other_callable) |> any($boolean_check); That would obviate the need to have proper methods on iterables as the combination of |> and higher order functions gives a similarly chainable syntax without the need to think about what objects have what methods on them at compile time. It's not perfect, but I think it's a good solution to a long-standing challenge. (Whether or not such higher order functions belong in the standard lib is debatable; it probably depends on what the performance difference is.) --Larry Garfield