Comment

Comment by mkdirp

That's what I was wondering too, especially considering there is a helper function that just wraps it. Seems rather unnecessary.

   <?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.
parent mkdirp 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton