Created
May 12, 2019 09:29
-
-
Save fatadz/5660df0e74d6eeed0eef3b9bad483d53 to your computer and use it in GitHub Desktop.
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 = func_get_args(); | |
return function($arg) use ($funcs) | |
{ | |
foreach($funcs as $function) { | |
if(!isset($value)) | |
$value = $function($arg); | |
else | |
$value = $function($value); | |
} | |
return $value; | |
}; | |
} | |
} | |
$fun = Pipeline::make_pipeline( | |
function($x) { return $x * 3; }, | |
function($x) { return $x + 1; }, | |
function($x) { return $x / 2; }); | |
echo $fun(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment