Last active
January 17, 2019 08:36
-
-
Save yohangdev/05e0e1e4f8ee5e4f4e4998b17327a306 to your computer and use it in GitHub Desktop.
PHP #2 - Pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Pipeline | |
| { | |
| public static function make_pipeline(...$funcs) | |
| { | |
| return function($arg) use ($funcs) | |
| { | |
| $x = $arg; | |
| foreach ($funcs as $func) { | |
| $x = call_user_func($func, $x); | |
| } | |
| return $x; | |
| }; | |
| } | |
| } | |
| $fun = Pipeline::make_pipeline( | |
| function($x) { | |
| return $x * 3; | |
| }, | |
| function($x) { | |
| return $x + 1; | |
| }, | |
| function($x) { | |
| return $x / 2; | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment