Created
January 15, 2021 14:45
-
-
Save sedera-tax/2cd9f131fdd9e1474ee180f263f7dd20 to your computer and use it in GitHub Desktop.
Make_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() | |
{ | |
return $result = function($arg) use ($funcs) | |
{ | |
foreach($funcs as $func) | |
{ | |
if(!isset($value)) | |
{ | |
$value = $func($arg); | |
} | |
else | |
{ | |
$value = $func($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); # should print 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment