Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Pipeline {
- public static function make_pipeline(...$funcs) {
- return function($arg) use ($funcs) {
- $output = NULL;
- if(count($funcs) > 0) {
- foreach($funcs as $key => $calculate) {
- if(is_callable($calculate)) {
- if(is_null($output)) {
- $output = $calculate($arg);
- } else {
- $output = $calculate($output);
- }
- }
- }
- }
- return $output;
- };
- }
- }
- $fun = Pipeline::make_pipeline(
- function($x) { return $x * 3; },
- function($x) { return $x + 1; },
- function($x) { return $x / 2; }
- );
- echo $fun(3); # should print 5
Add Comment
Please, Sign In to add comment