2021-06-07 21:00 GMT+02:00, Larry Garfield <la...@garfieldtech.com>:
> Hi folks. Me again.
>
> A year ago, I posted an RFC for a pipe operator, |>, aka function
> concatenation.  At the time, the main thrust of the feedback was "cool,
> like, but we need partial function application first so that the syntax for
> callables isn't so crappy."
>
> The PFA RFC is winding down now and is looking quite good, so it's time to
> revisit pipes.
>
> https://wiki.php.net/rfc/pipe-operator-v2
>
> Nothing radical has changed in the proposal since last year.  I have updated
> it against the latest master.  I also updated the RFC to use more examples
> that assume PFA, as the result is legit much nicer.  i also tested it
> locally with a combined partials-and-pipes branch to make sure they play
> nicely together, and they do.  (Yay!)  Assuming PFA passes I will include
> those tests in the pipes branch before this one goes to a vote.
>
> --
>   Larry Garfield
>   la...@garfieldtech.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php

Hi ho,

Has it been discussed the difference between the pipe operator and a
simple pipe function? Something like

function pipe() {
    $args = func_get_args();
    $result = $args[0];
    $functions = array_slice($args, 1);
    foreach ($functions as $function) {
        $result = $function($result);
    }
    return $result;
}

Usage (ignoring the pesky undefined constant warnings ><):

$result = pipe(
    "Hello world",
    htmlentities,
    str_split,
    fn ($x) => array_map(strtoupper, $x),
    fn ($x) => array_filter($x, fn ($v) => $v !== 'O')
);

There's also pipe operator with object, but that's obviously too
verbose compared to the operator
(https://github.com/sebastiaanluca/php-pipe-operator).

Olle

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

Reply via email to