@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @return array |
57 | 57 | */ |
58 | 58 | function filter() { |
59 | - $filter = function($fn, $list){ |
|
59 | + $filter = function($fn, $list) { |
|
60 | 60 | return array_values(array_filter($list, $fn)); |
61 | 61 | }; |
62 | 62 | return apply(curry($filter), func_get_args()); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return array |
79 | 79 | */ |
80 | 80 | function reduce() { |
81 | - $reduce = function($fn, $initial, $list){ |
|
81 | + $reduce = function($fn, $initial, $list) { |
|
82 | 82 | return array_reduce($list, $fn, $initial); |
83 | 83 | }; |
84 | 84 | return apply(curry($reduce), func_get_args()); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return array |
105 | 105 | */ |
106 | 106 | function each() { |
107 | - $each = function($fn, $list){ |
|
107 | + $each = function($fn, $list) { |
|
108 | 108 | foreach ($list as $item) { |
109 | 109 | apply($fn, [$item]); |
110 | 110 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | 130 | function head($list) { |
131 | - if(is_string($list)) |
|
131 | + if (is_string($list)) |
|
132 | 132 | return substr($list, 0, 1); |
133 | 133 | return (count($list) > 0) |
134 | 134 | ? $list[0] |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return mixed |
151 | 151 | */ |
152 | 152 | function last($list) { |
153 | - if(is_string($list)) |
|
153 | + if (is_string($list)) |
|
154 | 154 | return substr($list, -1); |
155 | 155 | return (count($list) > 0) |
156 | 156 | ? $list[count($list) - 1] |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return array |
174 | 174 | */ |
175 | 175 | function init($list) { |
176 | - if(is_string($list)) |
|
176 | + if (is_string($list)) |
|
177 | 177 | return (strlen($list) > 1) |
178 | 178 | ? substr($list, 0, strlen($list) - 1) |
179 | 179 | : ''; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return array |
199 | 199 | */ |
200 | 200 | function tail($list) { |
201 | - if(is_string($list)) |
|
201 | + if (is_string($list)) |
|
202 | 202 | return (strlen($list) > 1) |
203 | 203 | ? substr($list, 1) |
204 | 204 | : ''; |
@@ -322,8 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | function concatAll() { |
324 | 324 | $concatAll = function($lists) { |
325 | - return length($lists) == 0 ? [] : |
|
326 | - reduce(concat(), head($lists), tail($lists)); |
|
325 | + return length($lists) == 0 ? [] : reduce(concat(), head($lists), tail($lists)); |
|
327 | 326 | }; |
328 | 327 | return apply(curry($concatAll), func_get_args()); |
329 | 328 | } |
@@ -402,7 +401,7 @@ discard block |
||
402 | 401 | * @return array |
403 | 402 | */ |
404 | 403 | function append() { |
405 | - $append = function ($item, $list) { |
|
404 | + $append = function($item, $list) { |
|
406 | 405 | return insert(length($list), $item, $list); |
407 | 406 | }; |
408 | 407 | return apply(curry($append), func_get_args()); |
@@ -449,7 +448,7 @@ discard block |
||
449 | 448 | $length = length($list); |
450 | 449 | if ($count > $length || $count < -$length) |
451 | 450 | return []; |
452 | - if(is_string($list)) { |
|
451 | + if (is_string($list)) { |
|
453 | 452 | return ($count >= 0) |
454 | 453 | ? substr($list, 0, $count) |
455 | 454 | : substr($list, $count); |
@@ -705,9 +704,9 @@ discard block |
||
705 | 704 | */ |
706 | 705 | function slices() { |
707 | 706 | $slices = function($size, $list) { |
708 | - if(empty($list)) |
|
707 | + if (empty($list)) |
|
709 | 708 | return is_string($list) ? '' : []; |
710 | - if(length($list) <= $size) |
|
709 | + if (length($list) <= $size) |
|
711 | 710 | return [$list]; |
712 | 711 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
713 | 712 | }; |
@@ -731,7 +730,7 @@ discard block |
||
731 | 730 | */ |
732 | 731 | function contains() { |
733 | 732 | $contains = function($item, $list) { |
734 | - return -1 != indexOf($item, $list); |
|
733 | + return - 1 != indexOf($item, $list); |
|
735 | 734 | }; |
736 | 735 | return apply(curry($contains), func_get_args()); |
737 | 736 | } |
@@ -780,7 +779,7 @@ discard block |
||
780 | 779 | function findLastIndex() { |
781 | 780 | $findLastIndex = function($predicate, $list) { |
782 | 781 | foreach (reverse(toPairs($list)) as $pair) { |
783 | - if($predicate($pair[1])) |
|
782 | + if ($predicate($pair[1])) |
|
784 | 783 | return $pair[0]; |
785 | 784 | } |
786 | 785 | return null; |
@@ -857,7 +856,7 @@ discard block |
||
857 | 856 | $index = findIndex(equals($item), $list); |
858 | 857 | } |
859 | 858 | return (false === $index || null === $index) |
860 | - ? -1 |
|
859 | + ? - 1 |
|
861 | 860 | : $index; |
862 | 861 | }; |
863 | 862 | return apply(curry($indexOf), func_get_args()); |
@@ -887,7 +886,7 @@ discard block |
||
887 | 886 | $index = findLastIndex(equals($item), $list); |
888 | 887 | } |
889 | 888 | return (false === $index || null === $index) |
890 | - ? -1 |
|
889 | + ? - 1 |
|
891 | 890 | : $index; |
892 | 891 | }; |
893 | 892 | return apply(curry($lastIndexOf), func_get_args()); |
@@ -972,7 +971,7 @@ discard block |
||
972 | 971 | $groupBy = function($fn, $list) { |
973 | 972 | return reduce(function($result, $item) use($fn) { |
974 | 973 | $index = $fn($item); |
975 | - if (! isset($result[$index])) |
|
974 | + if (!isset($result[$index])) |
|
976 | 975 | $result[$index] = []; |
977 | 976 | $result[$index][] = $item; |
978 | 977 | return $result; |
@@ -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,10 +382,12 @@ 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; |
|
382 | - if ($position < 0) |
|
383 | - $position = 0; |
|
385 | + if ($position < 0) { |
|
386 | + $position = $length + $position; |
|
387 | + } |
|
388 | + if ($position < 0) { |
|
389 | + $position = 0; |
|
390 | + } |
|
384 | 391 | return ($position >= $length) |
385 | 392 | ? concat($list, $items) |
386 | 393 | : concatAll([take($position, $list), $items, remove($position, $list)]); |
@@ -447,8 +454,9 @@ discard block |
||
447 | 454 | function take() { |
448 | 455 | $take = function($count, $list) { |
449 | 456 | $length = length($list); |
450 | - if ($count > $length || $count < -$length) |
|
451 | - return []; |
|
457 | + if ($count > $length || $count < -$length) { |
|
458 | + return []; |
|
459 | + } |
|
452 | 460 | if(is_string($list)) { |
453 | 461 | return ($count >= 0) |
454 | 462 | ? substr($list, 0, $count) |
@@ -573,8 +581,9 @@ discard block |
||
573 | 581 | function remove() { |
574 | 582 | $remove = function($count, $list) { |
575 | 583 | $length = length($list); |
576 | - if ($count > $length || $count < -$length) |
|
577 | - return []; |
|
584 | + if ($count > $length || $count < -$length) { |
|
585 | + return []; |
|
586 | + } |
|
578 | 587 | return ($count > 0) |
579 | 588 | ? take($count - $length, $list) |
580 | 589 | : take($count + $length, $list); |
@@ -705,10 +714,12 @@ discard block |
||
705 | 714 | */ |
706 | 715 | function slices() { |
707 | 716 | $slices = function($size, $list) { |
708 | - if(empty($list)) |
|
709 | - return is_string($list) ? '' : []; |
|
710 | - if(length($list) <= $size) |
|
711 | - return [$list]; |
|
717 | + if(empty($list)) { |
|
718 | + return is_string($list) ? '' : []; |
|
719 | + } |
|
720 | + if(length($list) <= $size) { |
|
721 | + return [$list]; |
|
722 | + } |
|
712 | 723 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
713 | 724 | }; |
714 | 725 | return apply(curry($slices), func_get_args()); |
@@ -754,8 +765,9 @@ discard block |
||
754 | 765 | function findIndex() { |
755 | 766 | $findIndex = function($predicate, $list) { |
756 | 767 | foreach ($list as $key => $value) { |
757 | - if ($predicate($value)) |
|
758 | - return $key; |
|
768 | + if ($predicate($value)) { |
|
769 | + return $key; |
|
770 | + } |
|
759 | 771 | } |
760 | 772 | return null; |
761 | 773 | }; |
@@ -780,8 +792,9 @@ discard block |
||
780 | 792 | function findLastIndex() { |
781 | 793 | $findLastIndex = function($predicate, $list) { |
782 | 794 | foreach (reverse(toPairs($list)) as $pair) { |
783 | - if($predicate($pair[1])) |
|
784 | - return $pair[0]; |
|
795 | + if($predicate($pair[1])) { |
|
796 | + return $pair[0]; |
|
797 | + } |
|
785 | 798 | } |
786 | 799 | return null; |
787 | 800 | }; |
@@ -972,8 +985,9 @@ discard block |
||
972 | 985 | $groupBy = function($fn, $list) { |
973 | 986 | return reduce(function($result, $item) use($fn) { |
974 | 987 | $index = $fn($item); |
975 | - if (! isset($result[$index])) |
|
976 | - $result[$index] = []; |
|
988 | + if (! isset($result[$index])) { |
|
989 | + $result[$index] = []; |
|
990 | + } |
|
977 | 991 | $result[$index][] = $item; |
978 | 992 | return $result; |
979 | 993 | }, [], $list); |