Why not a pipe() function?
Closed this issue · 1 comments
olleharstedt commented
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. ^^
olleharstedt commented
OK, I can answer this myself:
-
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 -
No way to pass a function as first-class without having a warning/error about constant collision.