Skip to content

Instantly share code, notes, and snippets.

@igun997
Created May 18, 2019 11:03
Show Gist options
  • Save igun997/6f1257634389605fe46744bf9f022eb5 to your computer and use it in GitHub Desktop.
Save igun997/6f1257634389605fe46744bf9f022eb5 to your computer and use it in GitHub Desktop.
BE_PHP #2
<?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