@@ -83,8 +83,9 @@ discard block |
||
| 83 | 83 | if ($isArray) |
| 84 | 84 | { |
| 85 | 85 | foreach ($list as $item) { |
| 86 | - if ($fn($item)) |
|
| 87 | - $result[] = $item; |
|
| 86 | + if ($fn($item)) { |
|
| 87 | + $result[] = $item; |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | 90 | return $result; |
| 90 | 91 | } |
@@ -257,7 +258,9 @@ discard block |
||
| 257 | 258 | function head() { |
| 258 | 259 | static $head = false; |
| 259 | 260 | $head = $head ?: curry(function($list) { |
| 260 | - if (isset($list[0])) return $list[0]; |
|
| 261 | + if (isset($list[0])) { |
|
| 262 | + return $list[0]; |
|
| 263 | + } |
|
| 261 | 264 | return is_string($list) ? '' : null; |
| 262 | 265 | }); |
| 263 | 266 | return _apply($head, func_get_args()); |
@@ -282,8 +285,9 @@ discard block |
||
| 282 | 285 | function last () { |
| 283 | 286 | static $last = false; |
| 284 | 287 | $last = $last ?: curry(function($list) { |
| 285 | - if(is_string($list)) |
|
| 286 | - return substr($list, -1); |
|
| 288 | + if(is_string($list)) { |
|
| 289 | + return substr($list, -1); |
|
| 290 | + } |
|
| 287 | 291 | $size = count($list); |
| 288 | 292 | return ($size > 0) |
| 289 | 293 | ? $list[$size - 1] |
@@ -346,10 +350,11 @@ discard block |
||
| 346 | 350 | function tail () { |
| 347 | 351 | static $tail = false; |
| 348 | 352 | $tail = $tail ?: curry(function($list) { |
| 349 | - if(is_string($list)) |
|
| 350 | - return (strlen($list) > 1) |
|
| 353 | + if(is_string($list)) { |
|
| 354 | + return (strlen($list) > 1) |
|
| 351 | 355 | ? substr($list, 1) |
| 352 | 356 | : ''; |
| 357 | + } |
|
| 353 | 358 | return (count($list) > 1) |
| 354 | 359 | ? array_slice($list, 1) |
| 355 | 360 | : []; |
@@ -424,8 +429,9 @@ discard block |
||
| 424 | 429 | static $allSatisfies = false; |
| 425 | 430 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
| 426 | 431 | foreach ($list as $item) { |
| 427 | - if (! $predicate($item)) |
|
| 428 | - return false; |
|
| 432 | + if (! $predicate($item)) { |
|
| 433 | + return false; |
|
| 434 | + } |
|
| 429 | 435 | } |
| 430 | 436 | return true; |
| 431 | 437 | }); |
@@ -451,8 +457,9 @@ discard block |
||
| 451 | 457 | static $anySatisfies = false; |
| 452 | 458 | $anySatisfies = $anySatisfies ?: curry(function($predicate, $list) { |
| 453 | 459 | foreach ($list as $item) { |
| 454 | - if ($predicate($item)) |
|
| 455 | - return true; |
|
| 460 | + if ($predicate($item)) { |
|
| 461 | + return true; |
|
| 462 | + } |
|
| 456 | 463 | } |
| 457 | 464 | return false; |
| 458 | 465 | }); |
@@ -477,8 +484,9 @@ discard block |
||
| 477 | 484 | function concat() { |
| 478 | 485 | static $concat = false; |
| 479 | 486 | $concat = $concat ?: curry(function($list1, $list2) { |
| 480 | - if (is_string($list1) && is_string($list2)) |
|
| 481 | - return $list1 . $list2; |
|
| 487 | + if (is_string($list1) && is_string($list2)) { |
|
| 488 | + return $list1 . $list2; |
|
| 489 | + } |
|
| 482 | 490 | return array_merge($list1, $list2); |
| 483 | 491 | }); |
| 484 | 492 | return _apply($concat, func_get_args()); |
@@ -500,10 +508,12 @@ discard block |
||
| 500 | 508 | function concatAll() { |
| 501 | 509 | static $concatAll = false; |
| 502 | 510 | $concatAll = $concatAll ?: curry(function($lists) { |
| 503 | - if (count($lists) == 0) |
|
| 504 | - return []; |
|
| 505 | - if (is_string($lists[0])) |
|
| 506 | - return implode('', $lists); |
|
| 511 | + if (count($lists) == 0) { |
|
| 512 | + return []; |
|
| 513 | + } |
|
| 514 | + if (is_string($lists[0])) { |
|
| 515 | + return implode('', $lists); |
|
| 516 | + } |
|
| 507 | 517 | return _apply('array_merge', $lists); |
| 508 | 518 | }); |
| 509 | 519 | return _apply($concatAll, func_get_args()); |
@@ -568,14 +578,17 @@ discard block |
||
| 568 | 578 | static $insertAll = false; |
| 569 | 579 | $insertAll = $insertAll ?: curry(function($position, $items, $list) { |
| 570 | 580 | $size = length($list); |
| 571 | - if ($position < 0) |
|
| 572 | - $position = $size + $position; |
|
| 573 | - if ($position < 0) |
|
| 574 | - $position = 0; |
|
| 575 | - if (is_string($list)) |
|
| 576 | - return ($position >= $size) |
|
| 581 | + if ($position < 0) { |
|
| 582 | + $position = $size + $position; |
|
| 583 | + } |
|
| 584 | + if ($position < 0) { |
|
| 585 | + $position = 0; |
|
| 586 | + } |
|
| 587 | + if (is_string($list)) { |
|
| 588 | + return ($position >= $size) |
|
| 577 | 589 | ? $list . $items |
| 578 | 590 | : substr($list, 0, $position) . $items . substr($list, $position); |
| 591 | + } |
|
| 579 | 592 | return ($position >= $size) |
| 580 | 593 | ? array_merge($list, $items) |
| 581 | 594 | : array_merge(array_slice($list, 0, $position), $items, array_slice($list, $position)); |
@@ -659,8 +672,9 @@ discard block |
||
| 659 | 672 | static $take = false; |
| 660 | 673 | $take = $take ?: curry(function($count, $list) { |
| 661 | 674 | $length = length($list); |
| 662 | - if ($count > $length || $count < -$length) |
|
| 663 | - return $list; |
|
| 675 | + if ($count > $length || $count < -$length) { |
|
| 676 | + return $list; |
|
| 677 | + } |
|
| 664 | 678 | if(is_string($list)) { |
| 665 | 679 | return ($count >= 0) |
| 666 | 680 | ? substr($list, 0, $count) |
@@ -694,8 +708,9 @@ discard block |
||
| 694 | 708 | $takeWhile = $takeWhile ?: curry(function($predicate, $list) { |
| 695 | 709 | $index = 0; |
| 696 | 710 | $size = length($list); |
| 697 | - while ($index < $size && $predicate($list[$index])) |
|
| 698 | - $index ++; |
|
| 711 | + while ($index < $size && $predicate($list[$index])) { |
|
| 712 | + $index ++; |
|
| 713 | + } |
|
| 699 | 714 | return array_slice($list, 0, $index); |
| 700 | 715 | }); |
| 701 | 716 | return _apply($takeWhile, func_get_args()); |
@@ -720,8 +735,9 @@ discard block |
||
| 720 | 735 | static $takeLastWhile = false; |
| 721 | 736 | $takeLastWhile = $takeLastWhile ?: curry(function($predicate, $list) { |
| 722 | 737 | $index = length($list) - 1; |
| 723 | - while ($index >= 0 && $predicate($list[$index])) |
|
| 724 | - $index --; |
|
| 738 | + while ($index >= 0 && $predicate($list[$index])) { |
|
| 739 | + $index --; |
|
| 740 | + } |
|
| 725 | 741 | return array_slice($list, $index + 1); |
| 726 | 742 | }); |
| 727 | 743 | return _apply($takeLastWhile, func_get_args()); |
@@ -748,8 +764,9 @@ discard block |
||
| 748 | 764 | $takeUntil = $takeUntil ?: curry(function($predicate, $list) { |
| 749 | 765 | $index = 0; |
| 750 | 766 | $size = length($list); |
| 751 | - while ($index < $size && !$predicate($list[$index])) |
|
| 752 | - $index ++; |
|
| 767 | + while ($index < $size && !$predicate($list[$index])) { |
|
| 768 | + $index ++; |
|
| 769 | + } |
|
| 753 | 770 | return array_slice($list, 0, $index); |
| 754 | 771 | }); |
| 755 | 772 | return _apply($takeUntil, func_get_args()); |
@@ -774,8 +791,9 @@ discard block |
||
| 774 | 791 | static $takeLastUntil = false; |
| 775 | 792 | $takeLastUntil = $takeLastUntil ?: curry(function($predicate, $list) { |
| 776 | 793 | $index = length($list) - 1; |
| 777 | - while ($index >= 0 && !$predicate($list[$index])) |
|
| 778 | - $index --; |
|
| 794 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
| 795 | + $index --; |
|
| 796 | + } |
|
| 779 | 797 | return array_slice($list, $index + 1); |
| 780 | 798 | }); |
| 781 | 799 | return _apply($takeLastUntil, func_get_args()); |
@@ -807,8 +825,9 @@ discard block |
||
| 807 | 825 | $remove = $remove ?: curry(function($count, $list) { |
| 808 | 826 | // ... |
| 809 | 827 | $length = length($list); |
| 810 | - if ($count > $length || $count < -$length) |
|
| 811 | - return []; |
|
| 828 | + if ($count > $length || $count < -$length) { |
|
| 829 | + return []; |
|
| 830 | + } |
|
| 812 | 831 | $count = ($count > 0) |
| 813 | 832 | ? $count - $length |
| 814 | 833 | : $count + $length; |
@@ -845,8 +864,9 @@ discard block |
||
| 845 | 864 | $removeWhile = $removeWhile ?: curry(function($predicate, $list) { |
| 846 | 865 | $index = 0; |
| 847 | 866 | $size = length($list); |
| 848 | - while ($index < $size && $predicate($list[$index])) |
|
| 849 | - $index ++; |
|
| 867 | + while ($index < $size && $predicate($list[$index])) { |
|
| 868 | + $index ++; |
|
| 869 | + } |
|
| 850 | 870 | return array_slice($list, $index); |
| 851 | 871 | }); |
| 852 | 872 | return _apply($removeWhile, func_get_args()); |
@@ -871,8 +891,9 @@ discard block |
||
| 871 | 891 | static $removeLastWhile = false; |
| 872 | 892 | $removeLastWhile = $removeLastWhile ?: curry(function($predicate, $list) { |
| 873 | 893 | $index = length($list) - 1; |
| 874 | - while ($index >= 0 && $predicate($list[$index])) |
|
| 875 | - $index --; |
|
| 894 | + while ($index >= 0 && $predicate($list[$index])) { |
|
| 895 | + $index --; |
|
| 896 | + } |
|
| 876 | 897 | return array_slice($list, 0, $index + 1); |
| 877 | 898 | }); |
| 878 | 899 | return _apply($removeLastWhile, func_get_args()); |
@@ -900,8 +921,9 @@ discard block |
||
| 900 | 921 | $removeUntil = $removeUntil ?: curry(function($predicate, $list) { |
| 901 | 922 | $index = 0; |
| 902 | 923 | $size = length($list); |
| 903 | - while ($index < $size && !$predicate($list[$index])) |
|
| 904 | - $index ++; |
|
| 924 | + while ($index < $size && !$predicate($list[$index])) { |
|
| 925 | + $index ++; |
|
| 926 | + } |
|
| 905 | 927 | return array_slice($list, $index); |
| 906 | 928 | }); |
| 907 | 929 | return _apply($removeUntil, func_get_args()); |
@@ -927,8 +949,9 @@ discard block |
||
| 927 | 949 | static $removeLastUntil = false; |
| 928 | 950 | $removeLastUntil = $removeLastUntil ?: curry(function($predicate, $list) { |
| 929 | 951 | $index = length($list) - 1; |
| 930 | - while ($index >= 0 && !$predicate($list[$index])) |
|
| 931 | - $index --; |
|
| 952 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
| 953 | + $index --; |
|
| 954 | + } |
|
| 932 | 955 | return array_slice($list, 0, $index + 1); |
| 933 | 956 | }); |
| 934 | 957 | return _apply($removeLastUntil, func_get_args()); |
@@ -981,8 +1004,9 @@ discard block |
||
| 981 | 1004 | static $slices = false; |
| 982 | 1005 | $slices = $slices ?: curry(function($size, &$list) { |
| 983 | 1006 | $length = length($list); |
| 984 | - if ($length == 0) |
|
| 985 | - return is_string($list) ? [''] : []; |
|
| 1007 | + if ($length == 0) { |
|
| 1008 | + return is_string($list) ? [''] : []; |
|
| 1009 | + } |
|
| 986 | 1010 | $start = 0; |
| 987 | 1011 | $result = []; |
| 988 | 1012 | $slicer = is_string($list) ? 'substr' : 'array_slice'; |
@@ -1043,8 +1067,9 @@ discard block |
||
| 1043 | 1067 | static $findIndex = false; |
| 1044 | 1068 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
| 1045 | 1069 | foreach ($list as $key => &$value) { |
| 1046 | - if ($predicate($value)) |
|
| 1047 | - return $key; |
|
| 1070 | + if ($predicate($value)) { |
|
| 1071 | + return $key; |
|
| 1072 | + } |
|
| 1048 | 1073 | } |
| 1049 | 1074 | return null; |
| 1050 | 1075 | }); |
@@ -1074,8 +1099,9 @@ discard block |
||
| 1074 | 1099 | $keys = array_keys($list); |
| 1075 | 1100 | $index = count($keys) - 1; |
| 1076 | 1101 | while ($index >= 0) { |
| 1077 | - if ($predicate($list[$keys[$index]])) |
|
| 1078 | - return $keys[$index]; |
|
| 1102 | + if ($predicate($list[$keys[$index]])) { |
|
| 1103 | + return $keys[$index]; |
|
| 1104 | + } |
|
| 1079 | 1105 | $index --; |
| 1080 | 1106 | } |
| 1081 | 1107 | return null; |
@@ -1102,8 +1128,9 @@ discard block |
||
| 1102 | 1128 | static $find = false; |
| 1103 | 1129 | $find = $find ?: curry(function($predicate, $list) { |
| 1104 | 1130 | foreach ($list as $key => &$value) { |
| 1105 | - if ($predicate($value)) |
|
| 1106 | - return $value; |
|
| 1131 | + if ($predicate($value)) { |
|
| 1132 | + return $value; |
|
| 1133 | + } |
|
| 1107 | 1134 | } |
| 1108 | 1135 | return null; |
| 1109 | 1136 | }); |
@@ -1131,8 +1158,9 @@ discard block |
||
| 1131 | 1158 | $keys = array_keys($list); |
| 1132 | 1159 | $index = count($keys) - 1; |
| 1133 | 1160 | while ($index >= 0) { |
| 1134 | - if ($predicate($list[$keys[$index]])) |
|
| 1135 | - return $list[$keys[$index]]; |
|
| 1161 | + if ($predicate($list[$keys[$index]])) { |
|
| 1162 | + return $list[$keys[$index]]; |
|
| 1163 | + } |
|
| 1136 | 1164 | $index --; |
| 1137 | 1165 | } |
| 1138 | 1166 | return null; |
@@ -1176,8 +1204,9 @@ discard block |
||
| 1176 | 1204 | $keys = array_keys($list); |
| 1177 | 1205 | $length = count($keys); |
| 1178 | 1206 | while ($index < $length) { |
| 1179 | - if (_equals($item, $list[$keys[$index]])) |
|
| 1180 | - return $keys[$index]; |
|
| 1207 | + if (_equals($item, $list[$keys[$index]])) { |
|
| 1208 | + return $keys[$index]; |
|
| 1209 | + } |
|
| 1181 | 1210 | $index ++; |
| 1182 | 1211 | } |
| 1183 | 1212 | return -1; |
@@ -1215,8 +1244,9 @@ discard block |
||
| 1215 | 1244 | $keys = array_keys($list); |
| 1216 | 1245 | $index = count($list) - 1; |
| 1217 | 1246 | while ($index >= 0) { |
| 1218 | - if (_equals($list[$keys[$index]], $item)) |
|
| 1219 | - return $keys[$index]; |
|
| 1247 | + if (_equals($list[$keys[$index]], $item)) { |
|
| 1248 | + return $keys[$index]; |
|
| 1249 | + } |
|
| 1220 | 1250 | $index --; |
| 1221 | 1251 | } |
| 1222 | 1252 | return -1; |
@@ -1316,8 +1346,9 @@ discard block |
||
| 1316 | 1346 | $result = []; |
| 1317 | 1347 | foreach($list as $item) { |
| 1318 | 1348 | $index = $fn($item); |
| 1319 | - if (! isset($result[$index])) |
|
| 1320 | - $result[$index] = []; |
|
| 1349 | + if (! isset($result[$index])) { |
|
| 1350 | + $result[$index] = []; |
|
| 1351 | + } |
|
| 1321 | 1352 | $result[$index][] = $item; |
| 1322 | 1353 | } |
| 1323 | 1354 | return $result; |
@@ -1346,8 +1377,9 @@ discard block |
||
| 1346 | 1377 | $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) { |
| 1347 | 1378 | $length1 = count($list1); |
| 1348 | 1379 | $length2 = count($list2); |
| 1349 | - if (0 == $length1 || 0 == $length2) |
|
| 1350 | - return []; |
|
| 1380 | + if (0 == $length1 || 0 == $length2) { |
|
| 1381 | + return []; |
|
| 1382 | + } |
|
| 1351 | 1383 | $result = []; |
| 1352 | 1384 | $index = 0; |
| 1353 | 1385 | $length = min($length1, $length2); |