@@ -72,8 +72,9 @@ discard block |
||
72 | 72 | $filter = $filter ?: curry(function($fn, $list) { |
73 | 73 | $result = []; |
74 | 74 | foreach ($list as $item) { |
75 | - if ($fn($item)) |
|
76 | - $result[] = $item; |
|
75 | + if ($fn($item)) { |
|
76 | + $result[] = $item; |
|
77 | + } |
|
77 | 78 | } |
78 | 79 | return $result; |
79 | 80 | }); |
@@ -154,7 +155,9 @@ discard block |
||
154 | 155 | function head() { |
155 | 156 | static $head = false; |
156 | 157 | $head = $head ?: curry(function($list) { |
157 | - if (isset($list[0])) return $list[0]; |
|
158 | + if (isset($list[0])) { |
|
159 | + return $list[0]; |
|
160 | + } |
|
158 | 161 | return is_string($list) ? '' : null; |
159 | 162 | }); |
160 | 163 | return _apply($head, func_get_args()); |
@@ -179,8 +182,9 @@ discard block |
||
179 | 182 | function last () { |
180 | 183 | static $last = false; |
181 | 184 | $last = $last ?: curry(function($list) { |
182 | - if(is_string($list)) |
|
183 | - return substr($list, -1); |
|
185 | + if(is_string($list)) { |
|
186 | + return substr($list, -1); |
|
187 | + } |
|
184 | 188 | $size = count($list); |
185 | 189 | return ($size > 0) |
186 | 190 | ? $list[$size - 1] |
@@ -243,10 +247,11 @@ discard block |
||
243 | 247 | function tail () { |
244 | 248 | static $tail = false; |
245 | 249 | $tail = $tail ?: curry(function($list) { |
246 | - if(is_string($list)) |
|
247 | - return (strlen($list) > 1) |
|
250 | + if(is_string($list)) { |
|
251 | + return (strlen($list) > 1) |
|
248 | 252 | ? substr($list, 1) |
249 | 253 | : ''; |
254 | + } |
|
250 | 255 | return (count($list) > 1) |
251 | 256 | ? array_slice($list, 1) |
252 | 257 | : []; |
@@ -321,8 +326,9 @@ discard block |
||
321 | 326 | static $allSatisfies = false; |
322 | 327 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
323 | 328 | foreach ($list as $item) { |
324 | - if (! $predicate($item)) |
|
325 | - return false; |
|
329 | + if (! $predicate($item)) { |
|
330 | + return false; |
|
331 | + } |
|
326 | 332 | } |
327 | 333 | return true; |
328 | 334 | }); |
@@ -348,8 +354,9 @@ discard block |
||
348 | 354 | static $anySatisfies = false; |
349 | 355 | $anySatisfies = $anySatisfies ?: curry(function($predicate, $list) { |
350 | 356 | foreach ($list as $item) { |
351 | - if ($predicate($item)) |
|
352 | - return true; |
|
357 | + if ($predicate($item)) { |
|
358 | + return true; |
|
359 | + } |
|
353 | 360 | } |
354 | 361 | return false; |
355 | 362 | }); |
@@ -374,8 +381,9 @@ discard block |
||
374 | 381 | function concat() { |
375 | 382 | static $concat = false; |
376 | 383 | $concat = $concat ?: curry(function($list1, $list2) { |
377 | - if (is_string($list1) && is_string($list2)) |
|
378 | - return $list1 . $list2; |
|
384 | + if (is_string($list1) && is_string($list2)) { |
|
385 | + return $list1 . $list2; |
|
386 | + } |
|
379 | 387 | return array_merge($list1, $list2); |
380 | 388 | }); |
381 | 389 | return _apply($concat, func_get_args()); |
@@ -397,10 +405,12 @@ discard block |
||
397 | 405 | function concatAll() { |
398 | 406 | static $concatAll = false; |
399 | 407 | $concatAll = $concatAll ?: curry(function($lists) { |
400 | - if (count($lists) == 0) |
|
401 | - return []; |
|
402 | - if (is_string($lists[0])) |
|
403 | - return implode('', $lists); |
|
408 | + if (count($lists) == 0) { |
|
409 | + return []; |
|
410 | + } |
|
411 | + if (is_string($lists[0])) { |
|
412 | + return implode('', $lists); |
|
413 | + } |
|
404 | 414 | return _apply('array_merge', $lists); |
405 | 415 | }); |
406 | 416 | return _apply($concatAll, func_get_args()); |
@@ -465,14 +475,17 @@ discard block |
||
465 | 475 | static $insertAll = false; |
466 | 476 | $insertAll = $insertAll ?: curry(function($position, $items, $list) { |
467 | 477 | $size = length($list); |
468 | - if ($position < 0) |
|
469 | - $position = $size + $position; |
|
470 | - if ($position < 0) |
|
471 | - $position = 0; |
|
472 | - if (is_string($list)) |
|
473 | - return ($position >= $size) |
|
478 | + if ($position < 0) { |
|
479 | + $position = $size + $position; |
|
480 | + } |
|
481 | + if ($position < 0) { |
|
482 | + $position = 0; |
|
483 | + } |
|
484 | + if (is_string($list)) { |
|
485 | + return ($position >= $size) |
|
474 | 486 | ? $list . $items |
475 | 487 | : substr($list, 0, $position) . $items . substr($list, $position); |
488 | + } |
|
476 | 489 | return ($position >= $size) |
477 | 490 | ? array_merge($list, $items) |
478 | 491 | : array_merge(array_slice($list, 0, $position), $items, array_slice($list, $position)); |
@@ -556,8 +569,9 @@ discard block |
||
556 | 569 | static $take = false; |
557 | 570 | $take = $take ?: curry(function($count, $list) { |
558 | 571 | $length = length($list); |
559 | - if ($count > $length || $count < -$length) |
|
560 | - return $list; |
|
572 | + if ($count > $length || $count < -$length) { |
|
573 | + return $list; |
|
574 | + } |
|
561 | 575 | if(is_string($list)) { |
562 | 576 | return ($count >= 0) |
563 | 577 | ? substr($list, 0, $count) |
@@ -591,8 +605,9 @@ discard block |
||
591 | 605 | $takeWhile = $takeWhile ?: curry(function($predicate, $list) { |
592 | 606 | $index = 0; |
593 | 607 | $size = length($list); |
594 | - while ($index < $size && $predicate($list[$index])) |
|
595 | - $index ++; |
|
608 | + while ($index < $size && $predicate($list[$index])) { |
|
609 | + $index ++; |
|
610 | + } |
|
596 | 611 | return array_slice($list, 0, $index); |
597 | 612 | }); |
598 | 613 | return _apply($takeWhile, func_get_args()); |
@@ -617,8 +632,9 @@ discard block |
||
617 | 632 | static $takeLastWhile = false; |
618 | 633 | $takeLastWhile = $takeLastWhile ?: curry(function($predicate, $list) { |
619 | 634 | $index = length($list) - 1; |
620 | - while ($index >= 0 && $predicate($list[$index])) |
|
621 | - $index --; |
|
635 | + while ($index >= 0 && $predicate($list[$index])) { |
|
636 | + $index --; |
|
637 | + } |
|
622 | 638 | return array_slice($list, $index + 1); |
623 | 639 | }); |
624 | 640 | return _apply($takeLastWhile, func_get_args()); |
@@ -645,8 +661,9 @@ discard block |
||
645 | 661 | $takeUntil = $takeUntil ?: curry(function($predicate, $list) { |
646 | 662 | $index = 0; |
647 | 663 | $size = length($list); |
648 | - while ($index < $size && !$predicate($list[$index])) |
|
649 | - $index ++; |
|
664 | + while ($index < $size && !$predicate($list[$index])) { |
|
665 | + $index ++; |
|
666 | + } |
|
650 | 667 | return array_slice($list, 0, $index); |
651 | 668 | }); |
652 | 669 | return _apply($takeUntil, func_get_args()); |
@@ -671,8 +688,9 @@ discard block |
||
671 | 688 | static $takeLastUntil = false; |
672 | 689 | $takeLastUntil = $takeLastUntil ?: curry(function($predicate, $list) { |
673 | 690 | $index = length($list) - 1; |
674 | - while ($index >= 0 && !$predicate($list[$index])) |
|
675 | - $index --; |
|
691 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
692 | + $index --; |
|
693 | + } |
|
676 | 694 | return array_slice($list, $index + 1); |
677 | 695 | }); |
678 | 696 | return _apply($takeLastUntil, func_get_args()); |
@@ -704,8 +722,9 @@ discard block |
||
704 | 722 | static $remove = false; |
705 | 723 | $remove = $remove ?: curry(function($count, $list) { |
706 | 724 | $length = length($list); |
707 | - if ($count > $length || $count < -$length) |
|
708 | - return is_string($list) ? '' : []; |
|
725 | + if ($count > $length || $count < -$length) { |
|
726 | + return is_string($list) ? '' : []; |
|
727 | + } |
|
709 | 728 | $count = ($count > 0) |
710 | 729 | ? $count - $length |
711 | 730 | : $count + $length; |
@@ -742,8 +761,9 @@ discard block |
||
742 | 761 | $removeWhile = $removeWhile ?: curry(function($predicate, $list) { |
743 | 762 | $index = 0; |
744 | 763 | $size = length($list); |
745 | - while ($index < $size && $predicate($list[$index])) |
|
746 | - $index ++; |
|
764 | + while ($index < $size && $predicate($list[$index])) { |
|
765 | + $index ++; |
|
766 | + } |
|
747 | 767 | return array_slice($list, $index); |
748 | 768 | }); |
749 | 769 | return _apply($removeWhile, func_get_args()); |
@@ -768,8 +788,9 @@ discard block |
||
768 | 788 | static $removeLastWhile = false; |
769 | 789 | $removeLastWhile = $removeLastWhile ?: curry(function($predicate, $list) { |
770 | 790 | $index = length($list) - 1; |
771 | - while ($index >= 0 && $predicate($list[$index])) |
|
772 | - $index --; |
|
791 | + while ($index >= 0 && $predicate($list[$index])) { |
|
792 | + $index --; |
|
793 | + } |
|
773 | 794 | return array_slice($list, 0, $index + 1); |
774 | 795 | }); |
775 | 796 | return _apply($removeLastWhile, func_get_args()); |
@@ -797,8 +818,9 @@ discard block |
||
797 | 818 | $removeUntil = $removeUntil ?: curry(function($predicate, $list) { |
798 | 819 | $index = 0; |
799 | 820 | $size = length($list); |
800 | - while ($index < $size && !$predicate($list[$index])) |
|
801 | - $index ++; |
|
821 | + while ($index < $size && !$predicate($list[$index])) { |
|
822 | + $index ++; |
|
823 | + } |
|
802 | 824 | return array_slice($list, $index); |
803 | 825 | }); |
804 | 826 | return _apply($removeUntil, func_get_args()); |
@@ -824,8 +846,9 @@ discard block |
||
824 | 846 | static $removeLastUntil = false; |
825 | 847 | $removeLastUntil = $removeLastUntil ?: curry(function($predicate, $list) { |
826 | 848 | $index = length($list) - 1; |
827 | - while ($index >= 0 && !$predicate($list[$index])) |
|
828 | - $index --; |
|
849 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
850 | + $index --; |
|
851 | + } |
|
829 | 852 | return array_slice($list, 0, $index + 1); |
830 | 853 | }); |
831 | 854 | return _apply($removeLastUntil, func_get_args()); |
@@ -878,8 +901,9 @@ discard block |
||
878 | 901 | static $slices = false; |
879 | 902 | $slices = $slices ?: curry(function($size, &$list) { |
880 | 903 | $length = length($list); |
881 | - if ($length == 0) |
|
882 | - return is_string($list) ? [''] : []; |
|
904 | + if ($length == 0) { |
|
905 | + return is_string($list) ? [''] : []; |
|
906 | + } |
|
883 | 907 | $start = 0; |
884 | 908 | $result = []; |
885 | 909 | $slicer = is_string($list) ? 'substr' : 'array_slice'; |
@@ -940,8 +964,9 @@ discard block |
||
940 | 964 | static $findIndex = false; |
941 | 965 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
942 | 966 | foreach ($list as $key => &$value) { |
943 | - if ($predicate($value)) |
|
944 | - return $key; |
|
967 | + if ($predicate($value)) { |
|
968 | + return $key; |
|
969 | + } |
|
945 | 970 | } |
946 | 971 | return null; |
947 | 972 | }); |
@@ -971,8 +996,9 @@ discard block |
||
971 | 996 | $keys = array_keys($list); |
972 | 997 | $index = count($keys) - 1; |
973 | 998 | while ($index >= 0) { |
974 | - if ($predicate($list[$keys[$index]])) |
|
975 | - return $keys[$index]; |
|
999 | + if ($predicate($list[$keys[$index]])) { |
|
1000 | + return $keys[$index]; |
|
1001 | + } |
|
976 | 1002 | $index --; |
977 | 1003 | } |
978 | 1004 | return null; |
@@ -999,8 +1025,9 @@ discard block |
||
999 | 1025 | static $find = false; |
1000 | 1026 | $find = $find ?: curry(function($predicate, $list) { |
1001 | 1027 | foreach ($list as $key => &$value) { |
1002 | - if ($predicate($value)) |
|
1003 | - return $value; |
|
1028 | + if ($predicate($value)) { |
|
1029 | + return $value; |
|
1030 | + } |
|
1004 | 1031 | } |
1005 | 1032 | return null; |
1006 | 1033 | }); |
@@ -1028,8 +1055,9 @@ discard block |
||
1028 | 1055 | $keys = array_keys($list); |
1029 | 1056 | $index = count($keys) - 1; |
1030 | 1057 | while ($index >= 0) { |
1031 | - if ($predicate($list[$keys[$index]])) |
|
1032 | - return $list[$keys[$index]]; |
|
1058 | + if ($predicate($list[$keys[$index]])) { |
|
1059 | + return $list[$keys[$index]]; |
|
1060 | + } |
|
1033 | 1061 | $index --; |
1034 | 1062 | } |
1035 | 1063 | return null; |
@@ -1073,8 +1101,9 @@ discard block |
||
1073 | 1101 | $keys = array_keys($list); |
1074 | 1102 | $length = count($keys); |
1075 | 1103 | while ($index < $length) { |
1076 | - if (_equals($item, $list[$keys[$index]])) |
|
1077 | - return $keys[$index]; |
|
1104 | + if (_equals($item, $list[$keys[$index]])) { |
|
1105 | + return $keys[$index]; |
|
1106 | + } |
|
1078 | 1107 | $index ++; |
1079 | 1108 | } |
1080 | 1109 | return -1; |
@@ -1112,8 +1141,9 @@ discard block |
||
1112 | 1141 | $keys = array_keys($list); |
1113 | 1142 | $index = count($list) - 1; |
1114 | 1143 | while ($index >= 0) { |
1115 | - if (_equals($list[$keys[$index]], $item)) |
|
1116 | - return $keys[$index]; |
|
1144 | + if (_equals($list[$keys[$index]], $item)) { |
|
1145 | + return $keys[$index]; |
|
1146 | + } |
|
1117 | 1147 | $index --; |
1118 | 1148 | } |
1119 | 1149 | return -1; |
@@ -1213,8 +1243,9 @@ discard block |
||
1213 | 1243 | $result = []; |
1214 | 1244 | foreach($list as $item) { |
1215 | 1245 | $index = $fn($item); |
1216 | - if (! isset($result[$index])) |
|
1217 | - $result[$index] = []; |
|
1246 | + if (! isset($result[$index])) { |
|
1247 | + $result[$index] = []; |
|
1248 | + } |
|
1218 | 1249 | $result[$index][] = $item; |
1219 | 1250 | } |
1220 | 1251 | return $result; |
@@ -1243,8 +1274,9 @@ discard block |
||
1243 | 1274 | $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) { |
1244 | 1275 | $length1 = count($list1); |
1245 | 1276 | $length2 = count($list2); |
1246 | - if (0 == $length1 || 0 == $length2) |
|
1247 | - return []; |
|
1277 | + if (0 == $length1 || 0 == $length2) { |
|
1278 | + return []; |
|
1279 | + } |
|
1248 | 1280 | $result = []; |
1249 | 1281 | $index = 0; |
1250 | 1282 | $length = min($length1, $length2); |