| @@ 11-22 (lines=12) @@ | ||
| 8 | * @param callable $_ |
|
| 9 | * @return callable |
|
| 10 | */ |
|
| 11 | function curry($_) |
|
| 12 | { |
|
| 13 | $args = func_get_args(); |
|
| 14 | $count = is_int($_) ? array_shift($args) + max(count($args) - 1, 0) : null; |
|
| 15 | $callable = array_shift($args); |
|
| 16 | ||
| 17 | if ($count === 0 || (!isset($count) && _number_of_required_params($callable) === 0)) { |
|
| 18 | return _make_function($callable); |
|
| 19 | } |
|
| 20 | ||
| 21 | return _curry_array_args($callable, $args, $count); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param callable $callable |
|
| @@ 39-50 (lines=12) @@ | ||
| 36 | * @param callable $_ |
|
| 37 | * @return callable |
|
| 38 | */ |
|
| 39 | function curry_right($_) |
|
| 40 | { |
|
| 41 | $args = func_get_args(); |
|
| 42 | $count = is_int($_) ? array_shift($args) + max(count($args) - 1, 0) : null; |
|
| 43 | $callable = array_shift($args); |
|
| 44 | ||
| 45 | if ($count === 0 || (!isset($count) && _number_of_required_params($callable) === 0)) { |
|
| 46 | return _make_function($callable); |
|
| 47 | } |
|
| 48 | ||
| 49 | return _curry_array_args($callable, $args, $count, false); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param callable $callable |
|