-
-
Save igun997/6f1257634389605fe46744bf9f022eb5 to your computer and use it in GitHub Desktop.
BE_PHP #2
This file contains 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)) | |
{ | |
$value = $funcs($arg); | |
} | |
else | |
{ | |
$value = $funcs($value); | |
} | |
} | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment