Skip to content

Instantly share code, notes, and snippets.

@arbaieffendi
Created May 15, 2019 13:23
Show Gist options
  • Save arbaieffendi/cb7861a2ca039299cc277d692af021ae to your computer and use it in GitHub Desktop.
Save arbaieffendi/cb7861a2ca039299cc277d692af021ae to your computer and use it in GitHub Desktop.
Implementation of make_pipeline method
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
foreach($funcs as $f){
$arg = $f($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