Skip to content

Instantly share code, notes, and snippets.

@kenjipm
Last active December 23, 2024 21:23
Show Gist options
  • Save kenjipm/265194faf8574a5bbb0fad970e926a21 to your computer and use it in GitHub Desktop.
Save kenjipm/265194faf8574a5bbb0fad970e926a21 to your computer and use it in GitHub Desktop.
As part of a data processing pipeline, complete the implementation of the make_pipeline method: The method should accept a variable number of functions, and it should return a new function that accepts one parameter $arg. The returned function should call the first function in the make_pipeline with the parameter $arg, and call the second functi…
<?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