Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120844 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81431 invoked from network); 18 Jul 2023 18:09:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jul 2023 18:09:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ACA22180546 for ; Tue, 18 Jul 2023 11:09:56 -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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Jul 2023 11:09:56 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7E72B5C006A for ; Tue, 18 Jul 2023 14:09:54 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 18 Jul 2023 14:09:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1689703794; x= 1689790194; bh=+ZFPlSMHEH/25GAZ8xo+rQD1HdUlDw6nm+Rw9RE+Q/E=; b=A CFkvmS+70IY68rFCYZvVKVb/Xxm6wcz0ETGpGaIYskxw30YwJuHg0f5ELb4c3Tzc kmQpa/DwMpkc8Q+ls59+hE/AqopHmGx7IWy+77wqHSG0YFXWHaP/7uJ01rm1yfTT eAXb2a3CEa9R+IAta1c+psXtVEp2mc+O+3O3JP+ylcAMcGwcwAP46vwRM/+wAaas d5LgmQKInpdJV7pFcMhsmZ0gZVoUxfnwOJnkfTcpb3DRSJyGVy972YSBbzvhFR7X 4DBUBr2pZCAoKvYwsD15jDvYpLPTyGse7hiYI/QTuLAedJ8O3U3J6VHzDg20lEDz VX27I/Z/ywh3+mpybfSQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1689703794; x=1689790194; bh=+ZFPlSMHEH/25 GAZ8xo+rQD1HdUlDw6nm+Rw9RE+Q/E=; b=xwWhPlMFKD0cvhAdRiDx8qDtS5j+t 2dIXvddRWREUez0vEroya07tO2yTUMyYRi9EEZceErYHo7/KUvWcR+47lS03q3s8 ABWENtkI7VmaOL7/5DKBti8LwIzjoKtF6eX6JKTftRLbxQMl6sz0rmlrnyTpkGJ4 06KlL4RqsY0fjrIAV/IsJRYtPE0qx6GnfzRuvRi9MQONfwpl86yNyQLuKCw/RPPy MoPw4iG+tR9GqX+cVZmcK4kA//8/dpcOOXKLB6sIESZosewFKohv1kWFruefQ46X tD5y1nz3UqdRJG/CfnsW4UxdOsFiNz3u2VJNuQRXl1aX2nAthvLZFuOQQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggdduudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpedvgfekgfduhffhjeeufeefgffhgfejvefgfeekkeek hfeluefgteejheekgefhveenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhphhhprd hnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9407217000A2; Tue, 18 Jul 2023 14:09:53 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-531-gfdfa13a06d-fm-20230703.001-gfdfa13a0 Mime-Version: 1.0 Message-ID: <014c449a-fa84-4fa2-bfec-518a8fdb4ff1@app.fastmail.com> In-Reply-To: References: <8055b366-32f1-4d2c-85d0-0cf665e6c8d3@app.fastmail.com> Date: Tue, 18 Jul 2023 18:08:08 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] pipes, scalar objects and on? From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jul 18, 2023, at 5:08 PM, Karoly Negyesi wrote: > My favorite pipeline is Elixir, where "The pipe operator |> passes the > result of an expression as the first parameter of another expression".. But > it works there because unlike with PHP, it's almost always the first > argument you want. If it's not the first argument you needed to do some > tricks which was only cleaned up in 2021 so now they do: > > 5 > |> then(&Enum.take(1..10, &1)) > |> Enum.reverse() > > but I digress. > > My problem here is... we actually need something that passes the RFC vote. > > What flexibility is missing here? Please don't top post. The main flexibility for callables is the ability to build a closure on the fly. For example, using $$ (which Hack does, and I insist on calling T_BLING) means that for array and string functions you still need to worry about parameter order. With a callable, you can effectively emulate Elixir's behavior if you want. For example, my FP library has a whole bunch of higher order functions that just return pipe-ready functions: https://github.com/Crell/fp/blob/master/src/array.php Which, with a pipe operator, would allow for: $result = $arr |> amap(trim(...)) |> afilter(is_int(...)) |> reduce(0, $fn) |> trim(...) // At this point it's a string and trim() is already unary, so we can just use it. ; Which is pretty nice, IMO. It "flows" nicely, supports both higher order functions and direct calls equally well, and allows for all kinds of further expansion that I haven't thought of yet. The Hack style would require thinking about the fact that array_map() and array_filter() take their arguments in reverse order from each other, which is just silly. This way, that problem goes away entirely. It also allows a pipe to be used as a quasi alternative to scalar methods, because (if we set aside visibility for the moment) a method is just a function with an implicit $this parameter. Callables and higher order functions make that a lot cleaner. The caveat is that it does add an extra step to use many of the existing array or string stdlib functions. However, that's work that can be done once. The link above is under 500 lines, heavily documented, and covers every array use case I've run into so far. Related improvements: * Writing a higher order function right now is rather cumbersome. There were two previous RFCs that would have made that vastly nicer (short-functions and auto-capture closures), but neither passed. They would have allowed for: function amap(callable $c) => fn (iterable $it): array { if (is_array($it)) { return array_map($c, $it); } $result = []; foreach ($it as $k => $v) { $result[$k] = $c($v); } return $result; }; Which I think is pretty nice. * PFA would give us the best of both worlds, as if you wanted you could do: $result = $arr |> array_map(trim(...), ?) |> array_filter(?, is_int(...)) |> array_reduce(?, $fn, 0) |> trim(...) ; So with PFA and callable pipes, we get both options. If pipe was just Hack-style, there would be no way to use higher order functions with it. So IMO, the ideal experience that gets almost everyone what they want would be if all four of the following had passed: https://wiki.php.net/rfc/short-functions https://wiki.php.net/rfc/auto-capture-closure https://wiki.php.net/rfc/partial_function_application https://wiki.php.net/rfc/pipe-operator-v2 They are all mutually-complementary, but also useful on their own, and were designed that way deliberately. Sadly, all four were declined. So yeah, it's great that there's renewed interest in pipes, but I've already sunk a ton of time into this space (as have many other people that helped with those RFCs) with nothing to show for it. Unless there's indication from a notable number of voters that they'd support it now, I'm reluctant to sink much more of my time (or anyone else's time) into something that has so far just run into brick walls. If any of the above has convinced someone that we should try any of these features again, please speak up. I seriously do want this functionality, but OSS spec work is not my favorite way to spend time. --Larry Garfield