Skip to content

Instantly share code, notes, and snippets.

@Reasno
Created January 18, 2018 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reasno/5ece42bb9080fd0c31d993c6578f1234 to your computer and use it in GitHub Desktop.
Save Reasno/5ece42bb9080fd0c31d993c6578f1234 to your computer and use it in GitHub Desktop.
ComposeMinxins for functional programing.
function composeMixins(callable ...$mixins)
{
return function(
$x = [],
callable $mix = null
) use ($mixins){
$mix = $mix ?? function(callable ...$fns) use ($x){
return array_reduce($fns, function($acc, $fn){
return call_user_func($fn, $acc);
}, $x);
};
$func = call_user_func_array($mix, $mixins );
return $func;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment