Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Created January 30, 2021 21:24
Show Gist options
  • Save stevebauman/7fbc551a2f32d54fa28281d2ead3804e to your computer and use it in GitHub Desktop.
Save stevebauman/7fbc551a2f32d54fa28281d2ead3804e to your computer and use it in GitHub Desktop.
Pipeline Challenge
<?php
function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
foreach ($funcs as $func) {
$arg = $func($arg);
}
return $arg;
};
}
$fun = 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