On Mon, Jun 2, 2025, at 3:41 PM, Dmitry Derepko wrote:
> 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)
Pipe and compose are importantly different operations. I've had user-space implementations of
both available for years in crell/fp: https://github.com/Crell/fp/blob/master/src/composition.php
I'd love to have a compose operator natively in PHP, too. The RFC for that is already written,
just needs code. I hope to formally propose it soon: https://wiki.php.net/rfc/function-composition
--Larry Garfield