@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param callable $fn |
| 81 | 81 | * @param int $argsCount |
| 82 | 82 | * @param array $boundArgs |
| 83 | - * @return callable |
|
| 83 | + * @return \Closure |
|
| 84 | 84 | */ |
| 85 | 85 | function _curried_function($fn, $argsCount, $boundArgs = []) { |
| 86 | 86 | return function() use($fn, $argsCount, $boundArgs) { |
@@ -152,8 +152,6 @@ discard block |
||
| 152 | 152 | * ``` |
| 153 | 153 | * |
| 154 | 154 | * @signature (*... -> a) -> [*] -> a |
| 155 | - * @param callable $fn |
|
| 156 | - * @param array $args |
|
| 157 | 155 | * @return mixed |
| 158 | 156 | */ |
| 159 | 157 | function apply() { |
@@ -59,8 +59,9 @@ discard block |
||
| 59 | 59 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 60 | 60 | $currentBoundArgsCount = count($currentBoundArgs); |
| 61 | 61 | $placeholderPosition = 0; |
| 62 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 63 | - $placeholderPosition ++; |
|
| 62 | + while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) { |
|
| 63 | + $placeholderPosition ++; |
|
| 64 | + } |
|
| 64 | 65 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 65 | 66 | $currentBoundArgs[] = $arg; |
| 66 | 67 | } else { // There is a placeholder and number of bound args > $fnArgsCount |
@@ -87,8 +88,9 @@ discard block |
||
| 87 | 88 | $boundArgs = _merge_args($argsCount, $boundArgs, func_get_args()); |
| 88 | 89 | $numberOfPlaceholders = count(array_filter($boundArgs, _f('_is_placeholder'))); |
| 89 | 90 | $numberOfGivenArgs = count($boundArgs) - $numberOfPlaceholders; |
| 90 | - if ($numberOfGivenArgs >= $argsCount) |
|
| 91 | - return call_user_func_array($fn, $boundArgs); |
|
| 91 | + if ($numberOfGivenArgs >= $argsCount) { |
|
| 92 | + return call_user_func_array($fn, $boundArgs); |
|
| 93 | + } |
|
| 92 | 94 | return _curried_function($fn, $argsCount, $boundArgs); |
| 93 | 95 | }; |
| 94 | 96 | } |
@@ -179,8 +181,9 @@ discard block |
||
| 179 | 181 | */ |
| 180 | 182 | function pipe() { |
| 181 | 183 | $fns = func_get_args(); |
| 182 | - if(count($fns) < 1) |
|
| 183 | - throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 184 | + if(count($fns) < 1) { |
|
| 185 | + throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 186 | + } |
|
| 184 | 187 | return curry(function () use ($fns) { |
| 185 | 188 | $result = _apply(array_shift($fns), func_get_args()); |
| 186 | 189 | foreach ($fns as $fn) { |
@@ -128,8 +128,9 @@ discard block |
||
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
| 130 | 130 | function head($list) { |
| 131 | - if(is_string($list)) |
|
| 132 | - return substr($list, 0, 1); |
|
| 131 | + if(is_string($list)) { |
|
| 132 | + return substr($list, 0, 1); |
|
| 133 | + } |
|
| 133 | 134 | return (count($list) > 0) |
| 134 | 135 | ? $list[0] |
| 135 | 136 | : null; |
@@ -150,8 +151,9 @@ discard block |
||
| 150 | 151 | * @return mixed |
| 151 | 152 | */ |
| 152 | 153 | function last($list) { |
| 153 | - if(is_string($list)) |
|
| 154 | - return substr($list, -1); |
|
| 154 | + if(is_string($list)) { |
|
| 155 | + return substr($list, -1); |
|
| 156 | + } |
|
| 155 | 157 | return (count($list) > 0) |
| 156 | 158 | ? $list[count($list) - 1] |
| 157 | 159 | : null; |
@@ -173,10 +175,11 @@ discard block |
||
| 173 | 175 | * @return array |
| 174 | 176 | */ |
| 175 | 177 | function init($list) { |
| 176 | - if(is_string($list)) |
|
| 177 | - return (strlen($list) > 1) |
|
| 178 | + if(is_string($list)) { |
|
| 179 | + return (strlen($list) > 1) |
|
| 178 | 180 | ? substr($list, 0, strlen($list) - 1) |
| 179 | 181 | : ''; |
| 182 | + } |
|
| 180 | 183 | return (count($list) > 1) |
| 181 | 184 | ? array_slice($list, 0, count($list) - 1) |
| 182 | 185 | : []; |
@@ -198,10 +201,11 @@ discard block |
||
| 198 | 201 | * @return array |
| 199 | 202 | */ |
| 200 | 203 | function tail($list) { |
| 201 | - if(is_string($list)) |
|
| 202 | - return (strlen($list) > 1) |
|
| 204 | + if(is_string($list)) { |
|
| 205 | + return (strlen($list) > 1) |
|
| 203 | 206 | ? substr($list, 1) |
| 204 | 207 | : ''; |
| 208 | + } |
|
| 205 | 209 | return (count($list) > 1) |
| 206 | 210 | ? array_slice($list, 1) |
| 207 | 211 | : []; |
@@ -302,8 +306,9 @@ discard block |
||
| 302 | 306 | $t1 = toString($list1); |
| 303 | 307 | $t2 = toString($list2); |
| 304 | 308 | // echo "Concating {$t1} and {$t2}", PHP_EOL; |
| 305 | - if (is_string($list1) && is_string($list2)) |
|
| 306 | - return $list1 . $list2; |
|
| 309 | + if (is_string($list1) && is_string($list2)) { |
|
| 310 | + return $list1 . $list2; |
|
| 311 | + } |
|
| 307 | 312 | return array_merge($list1, $list2); |
| 308 | 313 | }; |
| 309 | 314 | return apply(curry($concat), func_get_args()); |
@@ -377,8 +382,9 @@ discard block |
||
| 377 | 382 | function insertAll() { |
| 378 | 383 | $insertAll = function($position, $items, $list) { |
| 379 | 384 | $length = length($list); |
| 380 | - if ($position < 0) |
|
| 381 | - $position = $length + $position; |
|
| 385 | + if ($position < 0) { |
|
| 386 | + $position = $length + $position; |
|
| 387 | + } |
|
| 382 | 388 | return ($position >= $length) |
| 383 | 389 | ? concat($list, $items) |
| 384 | 390 | : concatAll([take($position, $list), $items, remove($position, $list)]); |
@@ -445,8 +451,9 @@ discard block |
||
| 445 | 451 | function take() { |
| 446 | 452 | $take = function($count, $list) { |
| 447 | 453 | $length = length($list); |
| 448 | - if ($count > $length || $count < -$length) |
|
| 449 | - return []; |
|
| 454 | + if ($count > $length || $count < -$length) { |
|
| 455 | + return []; |
|
| 456 | + } |
|
| 450 | 457 | if(is_string($list)) { |
| 451 | 458 | return ($count >= 0) |
| 452 | 459 | ? substr($list, 0, $count) |
@@ -571,8 +578,9 @@ discard block |
||
| 571 | 578 | function remove() { |
| 572 | 579 | $remove = function($count, $list) { |
| 573 | 580 | $length = length($list); |
| 574 | - if ($count > $length || $count < -$length) |
|
| 575 | - return []; |
|
| 581 | + if ($count > $length || $count < -$length) { |
|
| 582 | + return []; |
|
| 583 | + } |
|
| 576 | 584 | return ($count > 0) |
| 577 | 585 | ? take($count - $length, $list) |
| 578 | 586 | : take($count + $length, $list); |
@@ -703,10 +711,12 @@ discard block |
||
| 703 | 711 | */ |
| 704 | 712 | function slices() { |
| 705 | 713 | $slices = function($size, $list) { |
| 706 | - if(empty($list)) |
|
| 707 | - return is_string($list) ? '' : []; |
|
| 708 | - if(length($list) <= $size) |
|
| 709 | - return [$list]; |
|
| 714 | + if(empty($list)) { |
|
| 715 | + return is_string($list) ? '' : []; |
|
| 716 | + } |
|
| 717 | + if(length($list) <= $size) { |
|
| 718 | + return [$list]; |
|
| 719 | + } |
|
| 710 | 720 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 711 | 721 | }; |
| 712 | 722 | return apply(curry($slices), func_get_args()); |
@@ -752,8 +762,9 @@ discard block |
||
| 752 | 762 | function findIndex() { |
| 753 | 763 | $findIndex = function($predicate, $list) { |
| 754 | 764 | foreach ($list as $key => $value) { |
| 755 | - if ($predicate($value)) |
|
| 756 | - return $key; |
|
| 765 | + if ($predicate($value)) { |
|
| 766 | + return $key; |
|
| 767 | + } |
|
| 757 | 768 | } |
| 758 | 769 | return null; |
| 759 | 770 | }; |
@@ -778,8 +789,9 @@ discard block |
||
| 778 | 789 | function findLastIndex() { |
| 779 | 790 | $findLastIndex = function($predicate, $list) { |
| 780 | 791 | foreach (reverse(toPairs($list)) as $pair) { |
| 781 | - if($predicate($pair[1])) |
|
| 782 | - return $pair[0]; |
|
| 792 | + if($predicate($pair[1])) { |
|
| 793 | + return $pair[0]; |
|
| 794 | + } |
|
| 783 | 795 | } |
| 784 | 796 | return null; |
| 785 | 797 | }; |
@@ -968,8 +980,9 @@ discard block |
||
| 968 | 980 | $groupBy = function($fn, $list) { |
| 969 | 981 | return reduce(function($result, $item) use($fn) { |
| 970 | 982 | $index = $fn($item); |
| 971 | - if (! isset($result[$index])) |
|
| 972 | - $result[$index] = []; |
|
| 983 | + if (! isset($result[$index])) { |
|
| 984 | + $result[$index] = []; |
|
| 985 | + } |
|
| 973 | 986 | $result[$index][] = $item; |
| 974 | 987 | return $result; |
| 975 | 988 | }, [], $list); |