Skip to content

Instantly share code, notes, and snippets.

@akatgelar
Last active September 23, 2021 06:02
Show Gist options
  • Save akatgelar/f4f223da7453f975997c4e1706618a7e to your computer and use it in GitHub Desktop.
Save akatgelar/f4f223da7453f975997c4e1706618a7e to your computer and use it in GitHub Desktop.
<?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); # should print 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment