document.write("
<?php
/**
* Our function to create a partial function. $func is
* a "callable", i.e. a closure or the name of a function, and
* $args is one or more arguments to bind to the function.
*
* @param $func - callable
* @param array ...$args
*
* @return \\Closure
*/
function partial( $func, ...$args ) {
return function() use( $func, $args ) {
/**
* Call the full function with a list of our
* bound arguments - $args
* calltime arguments - func_get_args()
*/
return \\call_user_func_array( $func, array_merge( $args, \\func_get_args() ) );
};
}
functions.php - Snippet hosted by \"Cacher\"
<?php
// You can "use" specific functions as well as classes
use function App\\Utils\\partial;
use function App\\Utils\\function_to_chain;
// so instead of
$result = \\App\\Utils\\partial( '\\App\\Utils\\function_to_chain', $var );
// we can have
$result = partial( 'function_to_chain', $var );
fp.php - Snippet hosted by \"Cacher\"
{
"autoload": {
"psr-4": {
"App\\\\" : "./src"
},
"files": [
"./src/App/Utils/functions.php"
]
}
}
composer.json - Snippet hosted by \"Cacher\"
");