Created
January 18, 2018 09:15
-
-
Save Reasno/5ece42bb9080fd0c31d993c6578f1234 to your computer and use it in GitHub Desktop.
ComposeMinxins for functional programing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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