Guest User

Untitled

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