sebastiaanluca/php-pipe-operator

Why not a pipe() function?

Closed this issue · 1 comments

Is there a specific reason you went for a pipe class instead of a simple pipe function, like:

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

Just curious. ^^

OK, I can answer this myself:

  1. A simple helper function pipe() to return new Pipe($val) makes this lib a bit nicer, as described here: https://medium.com/@liamhammett/php-function-chaining-with-pipes-a5c637587d7d

  2. No way to pass a function as first-class without having a warning/error about constant collision.