Re: [RFC] Pipe Operator (again)
| From: | Dmitry Derepko | Date: | Mon, 02 Jun 2025 20:41:44 +0000 |
| Subject: | Re: [RFC] Pipe Operator (again) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127541@lists.php.net to get a copy of this message | ||
Hi Larry!
It's been a long, long way to get this feature, awesome work.
Have you considered adding a compose function that does the same thing but
in the classic PHP function style?
There's not much difference between the new style:
$processor = fn ($data) => htmlentities($data)
|> str_split(...),
|> fn($x) => array_map(strtoupper(...), $x),
|> fn($x) => array_filter($x, fn($v) => $v != 'O’);
and the old one:
$processor = compose(
htmlentities(...),
str_split(...),
fn ($x) => array_map(strtoupper(...), $x),
fn ($x) => array_filter($x, fn ($v) => $v != 'O'),
);
But the classic looks better when you create real pipes.
I’ve created examples with comparison.
https://3v4l.org/jY0Vg
https://3v4l.org/87Sj2
https://3v4l.org/4EE6b
New syntax just makes code shorter, but the compose function still have
benefits:
- it will be able to add a polyfill for older versions
- it will be possible to write the first function without passing the first
argument ($data in the "fn ($data) => htmlentities($data)”)
- it will be possible to re-use the compose function along with the new
operator $data |> compose(…$functions)
----------
Best regards,
Dmitrii Derepko.
@xepozz