Why wrapped in a class? Seems entirely redundant or am I missing something?
<?php
function pipe(...$args) {
// Retrive first argument as initial value
$value = array_shift($args);
// Call the functions passing $value and assign its return
foreach($args as $func) $value = $func($value);
// Return computed value
return $value;
}
echo pipe("10 WAYS to EAT more HEALTHY",
fn($s) => strtolower($s),
fn($s) => str_replace(" ", "-", $s)
);
Works just as well.Here's my version in only 66 bytes, what do I win? ;)
<?php function pipe($v,...$p){foreach($p as$f)$v=$f($v);return$v;} <?php $pipe=fn($v,...$p)=>array_reduce($p,fn($a,$f)=>$f($a),$v);