Skip to content

Instantly share code, notes, and snippets.

@AkiraYuuji
Created May 17, 2019 07:29
Show Gist options
  • Save AkiraYuuji/6328b30a367bfd9cc11a6f306aaa5e8d to your computer and use it in GitHub Desktop.
Save AkiraYuuji/6328b30a367bfd9cc11a6f306aaa5e8d to your computer and use it in GitHub Desktop.
<?php
class Pipeline
{
public static function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
{
foreach($funcs as $list)
{
if(!isset($value))
{
$value = $list($arg);
}else
{
$value = $list($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