Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 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. $fn_num = sizeof($funcs);
  9. $result = $arg;
  10. for ($i = 0; $i < $fn_num; $i++){
  11. $result = $funcs[$i]($result);
  12. }
  13. return $result;
  14. };
  15. }
  16. }
  17.  
  18. $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
  19. function($x) { return $x / 2; });
  20. echo $fun(3); # should print 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement