Advertisement
Guest User

Untitled

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