Re: [RFC] Pipe Operator

From: Date: Tue, 03 May 2016 04:49:25 +0000
Subject: Re: [RFC] Pipe Operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-93036@lists.php.net to get a copy of this message
On Mon, May 2, 2016 at 5:57 PM, Stephen Coakley <me@stephencoakley.com> wrote: > Could you use a closure instead to accomplish this? (Again yes, Sara could > you clarify if this is permitted?) > > $ret = scandir($arg) > |> array_filter($$, function($x) { return $x !== '.' && $x != > '..'; > }) > |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, > $$) > |> (function($fileList) { > if (someCheck($fileList)) { > something(); > } > return $fileList; > })($$) > |> getFileArg($$) > |> array_merge($ret, $$); > You could, but IMO you lose a lot of the elegance if you go that route. This syntax works best when you have a series of functions which /don't/ have failure cases (and many many functions don't), or who fail via exceptions. Using current syntax, the above would look like: $ret = array_merge($ret, getFileArg(function($fileList) { if (someCheck($fileList)) { something(); } return $fileList; })(array_map(function($x) use ($arg) { return $arg . '/' . $x; }, array_filter(scandir($arg), function($x) { return $x !== '.' && $x !== '..'; })) ))); It's way more readable in the pipe syntax version, but it's overloading a single statement in both places. -Sara

« previous php.internals (#93036) next »