| <?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() ) ); |
| }; |
| } |
| <?php |
| |
| use function App\\Utils\\partial; |
| use function App\\Utils\\function_to_chain; |
| |
| |
| $result = \\App\\Utils\\partial( '\\App\\Utils\\function_to_chain', $var ); |
| |
| $result = partial( 'function_to_chain', $var ); |