Skip to content

Instantly share code, notes, and snippets.

@dikiwidia
Created May 14, 2019 16:29
Show Gist options
  • Save dikiwidia/3a65d4c58e541899cd3f8145197be430 to your computer and use it in GitHub Desktop.
Save dikiwidia/3a65d4c58e541899cd3f8145197be430 to your computer and use it in GitHub Desktop.
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
//Gunakan Foreach
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