On Mon, May 2, 2016 at 5:57 PM, Stephen Coakley <m...@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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to