SHARE
TWEET

Untitled

a guest Jan 17th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Pipeline {
  3.     public static function make_pipeline(...$funcs) {
  4.         return function($arg) use ($funcs) {
  5.             $result = $funcs[0]($arg);
  6.             for ($i = 1; $i < sizeof($funcs); $i++) {
  7.                 $result = $funcs[$i]($result);
  8.             }
  9.             return $result;
  10.         };
  11.     }
  12. }
  13.  
  14. $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
  15.                           function($x) { return $x / 2; });
  16. 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