Created
January 20, 2019 05:39
-
-
Save atyahyde/1a9db372653e2b166fcbb8367708f51f to your computer and use it in GitHub Desktop.
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() | |
{ | |
$func_list = func_get_args(); | |
$result = function($arg) use ($func_list) | |
{ | |
foreach($func_list as $funcs) | |
{ | |
if(!isset($value)) | |
{ | |
echo "set value!\n"; | |
$value = $funcs($arg); | |
} | |
else | |
{ | |
echo "update value!\n"; | |
$value = $funcs($value); | |
} | |
echo "Argument $value is: " . $value . "\n"; | |
} | |
return $value; | |
}; | |
return $result; | |
} | |
} | |
$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 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment