Skip to content

Instantly share code, notes, and snippets.

@yohangdev
Last active January 17, 2019 08:36
Show Gist options
  • Select an option

  • Save yohangdev/05e0e1e4f8ee5e4f4e4998b17327a306 to your computer and use it in GitHub Desktop.

Select an option

Save yohangdev/05e0e1e4f8ee5e4f4e4998b17327a306 to your computer and use it in GitHub Desktop.
PHP #2 - Pipeline
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
$x = $arg;
foreach ($funcs as $func) {
$x = call_user_func($func, $x);
}
return $x;
};
}
}
$fun = Pipeline::make_pipeline(
function($x) {
return $x * 3;
},
function($x) {
return $x + 1;
},
function($x) {
return $x / 2;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment