Skip to content

Instantly share code, notes, and snippets.

@ahikmatf
Created May 16, 2019 07:07
Show Gist options
  • Save ahikmatf/9436f82b29f1e0e31ae3ef88bd8df1ed to your computer and use it in GitHub Desktop.
Save ahikmatf/9436f82b29f1e0e31ae3ef88bd8df1ed to your computer and use it in GitHub Desktop.
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
$temporaryResult = $arg;
foreach ($funcs as $func) {
$temporaryResult = $func($temporaryResult);
}
return $temporaryResult;
};
}
}
$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