Skip to content

Instantly share code, notes, and snippets.

@malikalichsan
Created January 3, 2019 03:38
Show Gist options
  • Save malikalichsan/868884cd2e7d8110e0d5264a1792fe82 to your computer and use it in GitHub Desktop.
Save malikalichsan/868884cd2e7d8110e0d5264a1792fe82 to your computer and use it in GitHub Desktop.
#Jabar Digital Services PHP Question 2
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function ($arg) use ($funcs)
{
foreach ($funcs as $function) {
if(!isset($value))
$value = $function($arg);
else
$value = $function($value);
}
return $value;
};
}
}
$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