Re: Pipe Operator v2

From: Date: Fri, 20 Jan 2017 14:43:01 +0000
Subject: Re: Pipe Operator v2
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-97891@lists.php.net to get a copy of this message
On mobile, sorry for top posting. Multiple $$ means the resulting closure will accept multple arguments. I'm definitely against dropping the ($$) on the right hand side because it would use non standard symbol lookup rules. $x = trim; This normally will look up a constant, and then apply barewords if it doesn't exist. Let's not go down the road of special casing things. On Jan 20, 2017 3:53 AM, "François Laupretre" <flaupretre@free.fr> wrote: > Le 19/01/2017 à 22:53, Levi Morrison a écrit : > >> On Thu, Jan 19, 2017 at 11:12 AM, François Laupretre <flaupretre@free.fr> >> wrote: >> >>> Le 19/01/2017 à 13:54, Levi Morrison a écrit : >>> >>>> The |> symbol would be the piping operator with >>>> these semantics: >>>> 1. Evaluate the left-hand side. >>>> 2. Evaluate the right-hand side. Assert that the result is >>>> callable. >>>> 3. Pass the result from 1. as the single argument to 2. >>>> >>> >>> May I suggest extending your 3rd rule to : when the right hand side has >>> the >>> form of a function call, insert the result from 1. as first argument of >>> 2. >>> This way, right hand side may specify additional arguments >>> >> If we only had |> this may be good but since we are also >> proposing >> $$ then this renders your suggestion unnecessary: >> >> $string |> trim($$) >> >> Would work just fine with no performance overhead. >> >> Additionally, you could write: >> >> $input |> array_map($fn, $$) >> >> Or: >> >> $input |> array_filter($$, $fn) >> >> Basically, $$ gives the flexibility of passing additional >> arguments >> and keeps |> simple. No need for additional rules for >> |>. >> > > Right, I just suggest to make the '$$' optional when used as first arg of > a rhs call. Except complex cases like array_xx() functions which will > generally require an explicit '$$', most cases will feature a '$$' as first > arg of a function call. This may be considered as better because more > explicit, but I think the case is prominent enough to justify this > 'shortcut'. > > Another question: Will you accept several occurences of '$$' in a RHS ? > > Last, a cosmetic suggestion : replace '$$' with '$<' (more explicit as > 'input data', imo). > > Regards > > François >

« previous php.internals (#97891) next »