@@ -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); |