Advertisement
Guest User

Untitled

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