Re: Pipe Operator v2

From: Date: Thu, 19 Jan 2017 23:08:35 +0000
Subject: Re: Pipe Operator v2
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-97885@lists.php.net to get a copy of this message
On Thu, Jan 19, 2017 at 5:54 AM, Levi Morrison <levim@php.net> wrote:
I've talked to you about this RFC off-list, but I figured I should mention it on-list as well. I think we should make |> and $$ two independent operators that work well together (rather than only together).
Firstly, Levi, can I say I really like this line of thinking at first sight. As long as we can avoid it becoming too cryptically Perlish... On 19/01/2017 22:17, Ryan Pallas wrote:
When you say assert the right hand side is callable, does that mean to call an object method, you would do [$obj, 'method']? What about functions, is it just the name like $str |> trim, or is it $str |> trim()?
This is a good point. The difference between the pipe operator as proposed by Sara and the combination of two separate operators is that in Sara's proposal you'd always write this: $str |> trim($$) But in Levi's proposal as I understand it, the right-hand side is not syntax, it's just constrained to be callable, so the simpler (but rather ugly) form would be: $str |> 'trim' On its own, trim($$) rather pointlessly wraps a function with one argument into another function, still with one argument, effectively short-hand for Closure::fromCallable('trim') [incidentally, fromCallable isn't actually listed in the documentation yet]. Since ($$) would leave a closure effectively unchanged, you could actually write: $str |> trim($$)($$)($$)($$) And interestingly, the $$ magic couldn't be used to turn a function with one argument into one with zero, because trim($$)($foo) actually executes the function. This all feels fiddly for the same reason I dislike generators being introduced with "function" rather than their own keyword: it's one syntax hiding behind another. Which is a shame, because as I say, I liked the general idea. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#97885) next »