Re: [RFC] Pre-draft for PipeOp v2
| From: | Sara Golemon | Date: | Wed, 27 Sep 2017 19:56:07 +0000 |
| Subject: | Re: [RFC] Pre-draft for PipeOp v2 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100791@lists.php.net to get a copy of this message | ||
On Thu, Sep 21, 2017 at 5:13 PM, Stanislav Malyshev <smalyshev@gmail.com> wrote:
> It'd be also nice then if we could have some syntax that allowed us to
> refer to functions/methods as callables - mostly for the benefit of the
> code readers and IDEs. I.e. you can do "hello" |> "strtoupper" and
> it's
> fine but it is not at all intuitive what you're doing sending one string
> into another. Same with "hello" |> [$this, 'bar']. Now, if we could do
> something like this:
> "hello" |> &{strtoupper}
> "hello" |> &{$this->bar}
>
Super-hacky implementation (that I wouldn't want to merge, but it
shows the syntax at work).
https://github.com/php/php-src/compare/master...sgolemon:lambda
which provides a form of both short-closures and partial functions.
Combined with also-super-hacky pipe diff from earlier, you get:
$x = "Hello"
|> &{strtoupper($0)}
|> &{ $0 . "world" }
|> &{strrev($0)};
var_dump($x);
// string(10) "dlrowOLLEH"
-Sara