SHARE
TWEET

Untitled

a guest May 24th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Pipeline
  3. {
  4.     public static function make_pipeline()
  5.     {
  6.        
  7.         $functions = func_get_args();
  8.  
  9.         return function($arg) use ($functions) {
  10.             foreach ($functions as $function) {
  11.                 if(!isset($value)) {
  12.                     $value = $function($arg);
  13.                 } else {
  14.                     $value = $function($value);
  15.                 }
  16.             }
  17.  
  18.             return $value;
  19.         };
  20.  
  21.        
  22.     }
  23. }
  24.  
  25. $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
  26.                           function($x) { return $x / 2; });
  27.  
  28. echo $fun(3); # should print 5
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top