Skip to content

Instantly share code, notes, and snippets.

@shintack
Created May 12, 2019 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shintack/ab337d01bcbb9a36b25b0ecb03846555 to your computer and use it in GitHub Desktop.
Save shintack/ab337d01bcbb9a36b25b0ecb03846555 to your computer and use it in GitHub Desktop.
Pipeline
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
foreach ($funcs as $func)
{
$arg = $func($arg);
}
return $arg;
};
}
}
$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