Guest User

Untitled

a guest
Jan 21st, 2019
68
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(...$funcs)
  5. {
  6. return function($arg) use ($funcs)
  7. {
  8. // looping all arguments
  9. foreach($funcs as $function)
  10. {
  11. // change arg value every loop
  12. $arg = $function($arg);
  13. }
  14. return $arg;
  15. };
  16. }
  17. }
  18.  
  19. $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
  20. function($x) { return $x / 2; });
  21. echo $fun(3); # should print 5
Add Comment
Please, Sign In to add comment