Guest User

Untitled

a guest
Jan 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 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. foreach($funcs as $func)
  9. {
  10. $arg = $func($arg);
  11. }
  12.  
  13. return $arg;
  14. };
  15. }
  16. }
  17.  
  18. $fun = Pipeline::make_pipeline(function($x) {
  19. return $x * 3;
  20. },
  21. function($x)
  22. {
  23. return $x + 1;
  24. },
  25. function($x) {
  26. return $x / 2;
  27. });
  28.  
  29. echo $fun(3); # should print 5
Add Comment
Please, Sign In to add comment