Advertisement
Guest User

Untitled

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