Guest User

Untitled

a guest
Jan 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2. class Pipeline
  3. {
  4. public static function make_pipeline(...$funcs)
  5. {
  6. return function($arg) use ($funcs)
  7. {
  8. // loop list function
  9. foreach($funcs as $function) {
  10. // check variable $value
  11. if(!isset($value))
  12. // run the function with param send
  13. $value = $function($arg);
  14. else
  15. // run the function with value after function
  16. $value = $function($value);
  17. }
  18. // send back value
  19. return $value;
  20. };
  21. }
  22. }
  23.  
  24. $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
  25. function($x) { return $x / 2; });
  26. echo $fun(3); # should print 5
Add Comment
Please, Sign In to add comment