Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127032 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id CD8F21A00BC for ; Thu, 3 Apr 2025 11:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743681385; bh=USHh/KDt1CFf8w0arZoFfySXJkwGZ67dmWN5sebt42E=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ISiZQmSaF6vv3SJB+S1nYBGRGhkbsgF4DQmab17hN2AjpmkH8wyDJcwgUnsylSXDP qMgikOehFfJ4Au1rRD8c0/mieh8bXD9y8Qj1RVcDUuux2nravts8qzMJhkMCcoQIUz 2zeFEHWLPXET1HfMijWHttXVDRmh5rzDRXtCRgMWJ0vfVetLwMdGQJ3ynWyH1jtD0G +WZ9bxPQIlMjynTyUZy0H/4nst89t9D5nnrHhQsNtHwijZp2R5AiQKvZ9BVUUu4LTQ cLwNf+VJWkEEFKt/hckMPMLB+1n40/vRC3tztSQQ6iaZh0HLaK9gueTbED4LrRODdi dVczF+FY9cgDQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3E50B180083 for ; Thu, 3 Apr 2025 11:56:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Apr 2025 11:56:23 +0000 (UTC) Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id 92764254020D for ; Thu, 3 Apr 2025 07:58:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Thu, 03 Apr 2025 07:58:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1743681529; x=1743767929; bh=f4E63P6fUhcRVVI3+VoisIwelaV9fjV1A59XOPTSnnI=; b= y6p5GbJ++l5JJeyPkzsqIsGwkfDrjEYpQb2YFTuyFlSAq4Ccs12oMb3KSxRt6+8b 4+HR9XM99kKHZ/B//QCFssanLabAwGvIwyqOVCtGrTAM8RF8S12JiHUyBeRoIuTR IufwXQTVKKh0jdUHpwJ6HgD8od4n+mkx2TAwnZrBE/mYE0AvbXG+lOeKwj3zgcAD HQhS5iRvkDlE38IboTngiXRkDzNQtuX/npyD2gI02DVTiC4LAEhYRFhxOkiTHrre 2NFdWTX6ADaLlT36t8rpvGYCIu8SBFmOA+hTCCq3v0kuywTolAdUUYB7KO12uywV 9yi0y4czQ8O9muHr5ONL9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743681529; x=1743767929; bh=f 4E63P6fUhcRVVI3+VoisIwelaV9fjV1A59XOPTSnnI=; b=qbF/ch5ijc4vnx6ab FO+1QyfAKQ4Un9KY74ZwaexsehmAhYEN3pdXuASamF/Gjdz0jSrFg91VBLUjvi3K u5lC5alAw27J9gh8fBtzSn1xVQcGsTO+mI78NLdLSHDP5XQk1rlL4GPUok+/gv+y MjrjCdQEdTJJEfYA2/LfTdpR1kNFyG0bmSHW/zESJH/dlCu0mlt4rhDutIFejRnh A+8quqQVeodkqg9K7F9bx7ZDTNGQsksWI5YChPYhWJ21r1MByRzR3BZnZRcrW9nC QGZHZlIlPUB7QevBvhWisZ/wVQD0T+MusWNfwLugl/VFVeCqnnbGId4vFE25fpfQ xCX8w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeekhedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeffkeevudffuddvheejvdefkeelfedtudegfeehjeduheeg ieduffeggeegveefheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 3 Apr 2025 07:58:48 -0400 (EDT) Message-ID: <92b7f1ea-900b-4438-bed7-3fd766bb2d61@rwec.co.uk> Date: Thu, 3 Apr 2025 12:58:46 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Pipe Operator (again) To: internals@lists.php.net References: <5efa2f02-dd1d-4d59-ae07-c75f193b4096@app.fastmail.com> Content-Language: en-GB In-Reply-To: <5efa2f02-dd1d-4d59-ae07-c75f193b4096@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 03/04/2025 08:22, Larry Garfield wrote: > However, it also received significant pushback off-list from folks who felt it was too much magic. I don't want to torpedo pipes on over-reaching. But without feedback from other voters, I don't know if this is over-reaching. Is it? Please, someone tell me which approach you'd be more willing to vote for. :-) At first, I thought Ilija's example looked pretty neat, but having thought about it a bit more, I think the "first-arg" approach makes a handful of cases nicer at the cost of a lot of magic, and making other cases worse. The right-hand side is magic in two ways: 1) it looks like an expression, but actually has to be a syntactic function call for the engine to inject an argument into 2) it looks like it's calling a function with the wrong arguments If we have a special case where the right-hand side *is* an expression, evaluated as a single-argument callable/Closure, that's even more scope for confusion. [cf my thoughts in the async thread about keeping the right-hand side of "spawn" consistent] The cases it makes nicer are where you are chaining existing functions with the placeholder as first (but not only) parameter. If you want to pipe into a non-first parameter, you have a few options: a) Write a new function or explicit wrapper - equally possible with either option // for first-arg chaining: function swapped_explode(string $string, string $separator): string { return explode($separator, $string); } $someChain |> swapped_explode(':'); // for only-arg chaining: function curried_explode(string $separator, string $string): callable { return fn(string $string) => explode($separator, $string); } $someChain |> curried_explode(':'); b) Use an immediate closure as the wrapper - only-arg chaining seems better // first-arg chaining $someChain |> fn($string) => explode(':', $string)(); // first-arg chaining with special case syntax for closures $someChain |> ( fn($string) => explode(':', $string) ); // for only-arg chaining: $someChain |> fn($string) => explode(':', $string); c) Use a new partial application syntax - same problem as immediate closure // for first-arg chaining $someChain |> explode(':', ?)(); // or with overloaded syntax $someChain |> ( explode(':', ?) ); // for only-arg chaining $someChain |> explode(':', ?); It's also quite easy to write a helper for the special-case of "partially apply all except the first argument": function partial_first(callable $fn, mixed ...$fixedArgs): callable {     return fn(mixed $firstArg) => $fn($firstArg, ...$fixedArgs); } // first-arg chaining $someChain |> array_filter(fn($v, $k) => $k === $v, ARRAY_FILTER_USE_BOTH); // native partial application $someChain |> array_filter(?, fn($v, $k) => $k === $v, ARRAY_FILTER_USE_BOTH); // workaround $someChain |> partial_first(array_filter(...), fn($v, $k) => $k === $v, ARRAY_FILTER_USE_BOTH)); -- Rowan Tommins [IMSoP]