Advertisement
Guest User

Untitled

a guest
May 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement