@@ -15,8 +15,6 @@ discard block |
||
| 15 | 15 | * @stream |
| 16 | 16 | * @signature (a -> b) -> [a] -> [b] |
| 17 | 17 | * @signature (a -> b) -> {k: a} -> {k: b} |
| 18 | - * @param callable $fn |
|
| 19 | - * @param array $list |
|
| 20 | 18 | * @return array |
| 21 | 19 | */ |
| 22 | 20 | function map() { |
@@ -36,8 +34,6 @@ discard block |
||
| 36 | 34 | * |
| 37 | 35 | * @stream |
| 38 | 36 | * @signature (a -> [b]) -> [a] -> [b] |
| 39 | - * @param callable $fn |
|
| 40 | - * @param array $list |
|
| 41 | 37 | * @return array |
| 42 | 38 | */ |
| 43 | 39 | function chain() { |
@@ -66,8 +62,6 @@ discard block |
||
| 66 | 62 | * ``` |
| 67 | 63 | * @stream |
| 68 | 64 | * @signature (a -> Boolean) -> [a] -> [a] |
| 69 | - * @param callable $fn |
|
| 70 | - * @param array|\ArrayObject|\SplObjectStorage $list |
|
| 71 | 65 | * @return array|\ArrayObject|\SplObjectStorage|callable |
| 72 | 66 | */ |
| 73 | 67 | function filter() { |
@@ -150,8 +144,6 @@ discard block |
||
| 150 | 144 | * ``` |
| 151 | 145 | * |
| 152 | 146 | * @signature (a -> Boolean) -> [a] -> [a] |
| 153 | - * @param callable $predicate |
|
| 154 | - * @param array|\ArrayObject|\SplObjectStorage $list |
|
| 155 | 147 | * @return array|\ArrayObject|\SplObjectStorage|callable |
| 156 | 148 | */ |
| 157 | 149 | function filter_values() { |
@@ -195,9 +187,6 @@ discard block |
||
| 195 | 187 | * |
| 196 | 188 | * @stream |
| 197 | 189 | * @signature (* -> a -> *) -> * -> [a] -> * |
| 198 | - * @param callable $fn |
|
| 199 | - * @param mixed $initial |
|
| 200 | - * @param array $list |
|
| 201 | 190 | * @return array |
| 202 | 191 | */ |
| 203 | 192 | function reduce() { |
@@ -223,8 +212,6 @@ discard block |
||
| 223 | 212 | * |
| 224 | 213 | * @stream |
| 225 | 214 | * @signature (a -> *) -> [a] -> [a] |
| 226 | - * @param callable $fn |
|
| 227 | - * @param array $list |
|
| 228 | 215 | * @return array |
| 229 | 216 | */ |
| 230 | 217 | function each() { |
@@ -251,7 +238,6 @@ discard block |
||
| 251 | 238 | * @stream |
| 252 | 239 | * @signature [a] -> a |
| 253 | 240 | * @signature String -> String |
| 254 | - * @param array|string $list |
|
| 255 | 241 | * @return mixed |
| 256 | 242 | */ |
| 257 | 243 | function head() { |
@@ -276,7 +262,6 @@ discard block |
||
| 276 | 262 | * @stream |
| 277 | 263 | * @signature [a] -> a |
| 278 | 264 | * @signature String -> String |
| 279 | - * @param array|string $list |
|
| 280 | 265 | * @return mixed |
| 281 | 266 | */ |
| 282 | 267 | function last () { |
@@ -306,7 +291,6 @@ discard block |
||
| 306 | 291 | * @stream |
| 307 | 292 | * @signature [a] -> a |
| 308 | 293 | * @signature String -> String |
| 309 | - * @param array|string $list |
|
| 310 | 294 | * @return array |
| 311 | 295 | */ |
| 312 | 296 | function init () { |
@@ -340,7 +324,6 @@ discard block |
||
| 340 | 324 | * @stream |
| 341 | 325 | * @signature [a] -> a |
| 342 | 326 | * @signature String -> String |
| 343 | - * @param array|string $list |
|
| 344 | 327 | * @return array |
| 345 | 328 | */ |
| 346 | 329 | function tail () { |
@@ -368,7 +351,6 @@ discard block |
||
| 368 | 351 | * @stream |
| 369 | 352 | * @signature [a] -> [a] |
| 370 | 353 | * @signature String -> String |
| 371 | - * @param array|string $list |
|
| 372 | 354 | * @return array |
| 373 | 355 | */ |
| 374 | 356 | function reverse () { |
@@ -392,7 +374,6 @@ discard block |
||
| 392 | 374 | * @stream |
| 393 | 375 | * @signature [a] -> Number |
| 394 | 376 | * @signature String -> Number |
| 395 | - * @param array|string $list |
|
| 396 | 377 | * @return int |
| 397 | 378 | */ |
| 398 | 379 | function length() { |
@@ -416,8 +397,6 @@ discard block |
||
| 416 | 397 | * |
| 417 | 398 | * @stream |
| 418 | 399 | * @signature (a -> Boolean) -> [a] -> Boolean |
| 419 | - * @param callable $predicate |
|
| 420 | - * @param array $list |
|
| 421 | 400 | * @return bool |
| 422 | 401 | */ |
| 423 | 402 | function allSatisfies() { |
@@ -443,8 +422,6 @@ discard block |
||
| 443 | 422 | * |
| 444 | 423 | * @stream |
| 445 | 424 | * @signature (a -> Boolean) -> [a] -> Boolean |
| 446 | - * @param callable $predicate |
|
| 447 | - * @param array $list |
|
| 448 | 425 | * @return bool |
| 449 | 426 | */ |
| 450 | 427 | function anySatisfies() { |
@@ -470,8 +447,6 @@ discard block |
||
| 470 | 447 | * @stream |
| 471 | 448 | * @signature [*] -> [*] -> [*] |
| 472 | 449 | * @signature String -> String -> String |
| 473 | - * @param array $list1 |
|
| 474 | - * @param array $list2 |
|
| 475 | 450 | * @return array |
| 476 | 451 | */ |
| 477 | 452 | function concat() { |
@@ -494,7 +469,6 @@ discard block |
||
| 494 | 469 | * |
| 495 | 470 | * @stream |
| 496 | 471 | * @signature [[a]] -> [a] |
| 497 | - * @param array $lists |
|
| 498 | 472 | * @return array |
| 499 | 473 | */ |
| 500 | 474 | function concatAll() { |
@@ -529,9 +503,6 @@ discard block |
||
| 529 | 503 | * @stream |
| 530 | 504 | * @signature Number -> a -> [a] -> [a] |
| 531 | 505 | * @signature Number -> String -> String -> String |
| 532 | - * @param int $position |
|
| 533 | - * @param mixed $item |
|
| 534 | - * @param array $list |
|
| 535 | 506 | * @return array |
| 536 | 507 | */ |
| 537 | 508 | function insert() { |
@@ -559,9 +530,6 @@ discard block |
||
| 559 | 530 | * @stream |
| 560 | 531 | * @signature Number -> [a] -> [a] -> [a] |
| 561 | 532 | * @signature Number -> String -> String -> String |
| 562 | - * @param int $position |
|
| 563 | - * @param mixed $items |
|
| 564 | - * @param array $list |
|
| 565 | 533 | * @return array |
| 566 | 534 | */ |
| 567 | 535 | function insertAll() { |
@@ -594,8 +562,6 @@ discard block |
||
| 594 | 562 | * @stream |
| 595 | 563 | * @signature * -> [*] -> [*] |
| 596 | 564 | * @signature String -> String -> String |
| 597 | - * @param mixed $item |
|
| 598 | - * @param array $list |
|
| 599 | 565 | * @return array |
| 600 | 566 | */ |
| 601 | 567 | function append() { |
@@ -620,8 +586,6 @@ discard block |
||
| 620 | 586 | * @stream |
| 621 | 587 | * @signature a -> [a] -> [a] |
| 622 | 588 | * @signature String -> String -> String |
| 623 | - * @param mixed $item |
|
| 624 | - * @param array $list |
|
| 625 | 589 | * @return array |
| 626 | 590 | */ |
| 627 | 591 | function prepend() { |
@@ -651,8 +615,6 @@ discard block |
||
| 651 | 615 | * @stream |
| 652 | 616 | * @signature Number -> [a] -> [a] |
| 653 | 617 | * @signature Number -> String -> String |
| 654 | - * @param int $count |
|
| 655 | - * @param array $list |
|
| 656 | 618 | * @return array |
| 657 | 619 | */ |
| 658 | 620 | function take() { |
@@ -685,8 +647,6 @@ discard block |
||
| 685 | 647 | * |
| 686 | 648 | * @stream |
| 687 | 649 | * @signature (a -> Boolean) -> [a] -> [a] |
| 688 | - * @param callable $predicate |
|
| 689 | - * @param array $list |
|
| 690 | 650 | * @return array |
| 691 | 651 | */ |
| 692 | 652 | function takeWhile() { |
@@ -712,8 +672,6 @@ discard block |
||
| 712 | 672 | * |
| 713 | 673 | * @stream |
| 714 | 674 | * @signature (a -> Boolean) -> [a] -> [a] |
| 715 | - * @param callable $predicate |
|
| 716 | - * @param array $list |
|
| 717 | 675 | * @return array |
| 718 | 676 | */ |
| 719 | 677 | function takeLastWhile() { |
@@ -739,8 +697,6 @@ discard block |
||
| 739 | 697 | * |
| 740 | 698 | * @stream |
| 741 | 699 | * @signature (a -> Boolean) -> [a] -> [a] |
| 742 | - * @param callable $predicate |
|
| 743 | - * @param array $list |
|
| 744 | 700 | * @return array |
| 745 | 701 | */ |
| 746 | 702 | function takeUntil() { |
@@ -766,8 +722,6 @@ discard block |
||
| 766 | 722 | * |
| 767 | 723 | * @stream |
| 768 | 724 | * @signature (a -> Boolean) -> [a] -> [a] |
| 769 | - * @param callable $predicate |
|
| 770 | - * @param array $list |
|
| 771 | 725 | * @return array |
| 772 | 726 | */ |
| 773 | 727 | function takeLastUntil() { |
@@ -798,8 +752,6 @@ discard block |
||
| 798 | 752 | * @stream |
| 799 | 753 | * @signature Number -> [a] -> [a] |
| 800 | 754 | * @signature Number -> String -> String |
| 801 | - * @param int $count |
|
| 802 | - * @param array $list |
|
| 803 | 755 | * @return array |
| 804 | 756 | */ |
| 805 | 757 | function remove() { |
@@ -836,8 +788,6 @@ discard block |
||
| 836 | 788 | * |
| 837 | 789 | * @stream |
| 838 | 790 | * @signature (a -> Boolean) -> [a] -> [a] |
| 839 | - * @param callable $predicate |
|
| 840 | - * @param array $list |
|
| 841 | 791 | * @return array |
| 842 | 792 | */ |
| 843 | 793 | function removeWhile() { |
@@ -863,8 +813,6 @@ discard block |
||
| 863 | 813 | * |
| 864 | 814 | * @stream |
| 865 | 815 | * @signature (a -> Boolean) -> [a] -> [a] |
| 866 | - * @param callable $predicate |
|
| 867 | - * @param array $list |
|
| 868 | 816 | * @return array |
| 869 | 817 | */ |
| 870 | 818 | function removeLastWhile() { |
@@ -891,8 +839,6 @@ discard block |
||
| 891 | 839 | * |
| 892 | 840 | * @stream |
| 893 | 841 | * @signature (a -> Boolean) -> [a] -> [a] |
| 894 | - * @param callable $predicate |
|
| 895 | - * @param array $list |
|
| 896 | 842 | * @return array |
| 897 | 843 | */ |
| 898 | 844 | function removeUntil() { |
@@ -919,8 +865,6 @@ discard block |
||
| 919 | 865 | * |
| 920 | 866 | * @stream |
| 921 | 867 | * @signature (a -> Boolean) -> [a] -> [a] |
| 922 | - * @param callable $predicate |
|
| 923 | - * @param array $list |
|
| 924 | 868 | * @return array |
| 925 | 869 | */ |
| 926 | 870 | function removeLastUntil() { |
@@ -943,7 +887,6 @@ discard block |
||
| 943 | 887 | * |
| 944 | 888 | * @stream |
| 945 | 889 | * @signature [(k, v)] -> {k: v} |
| 946 | - * @param array $pairs |
|
| 947 | 890 | * @return stdClass |
| 948 | 891 | */ |
| 949 | 892 | function fromPairs() { |
@@ -973,8 +916,6 @@ discard block |
||
| 973 | 916 | * @stream |
| 974 | 917 | * @signature Number -> [a] -> [[a]] |
| 975 | 918 | * @signature Number -> String -> [String] |
| 976 | - * @param int $size |
|
| 977 | - * @param array $list |
|
| 978 | 919 | * @return array |
| 979 | 920 | */ |
| 980 | 921 | function slices() { |
@@ -1008,8 +949,6 @@ discard block |
||
| 1008 | 949 | * @stream |
| 1009 | 950 | * @signature a -> [a] -> Boolean |
| 1010 | 951 | * @signature String -> String -> Boolean |
| 1011 | - * @param mixed $item |
|
| 1012 | - * @param array|string $list |
|
| 1013 | 952 | * @return bool |
| 1014 | 953 | */ |
| 1015 | 954 | function contains() { |
@@ -1035,8 +974,6 @@ discard block |
||
| 1035 | 974 | * @stream |
| 1036 | 975 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
| 1037 | 976 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
| 1038 | - * @param callable $predicate |
|
| 1039 | - * @param array $list |
|
| 1040 | 977 | * @return mixed |
| 1041 | 978 | */ |
| 1042 | 979 | function findIndex() { |
@@ -1064,8 +1001,6 @@ discard block |
||
| 1064 | 1001 | * @stream |
| 1065 | 1002 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
| 1066 | 1003 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
| 1067 | - * @param callable $predicate |
|
| 1068 | - * @param array $list |
|
| 1069 | 1004 | * @return mixed |
| 1070 | 1005 | */ |
| 1071 | 1006 | function findLastIndex() { |
@@ -1094,8 +1029,6 @@ discard block |
||
| 1094 | 1029 | * |
| 1095 | 1030 | * @stream |
| 1096 | 1031 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
| 1097 | - * @param callable $predicate |
|
| 1098 | - * @param array $list |
|
| 1099 | 1032 | * @return mixed |
| 1100 | 1033 | */ |
| 1101 | 1034 | function find() { |
@@ -1121,8 +1054,6 @@ discard block |
||
| 1121 | 1054 | * |
| 1122 | 1055 | * @stream |
| 1123 | 1056 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
| 1124 | - * @param callable $predicate |
|
| 1125 | - * @param array $list |
|
| 1126 | 1057 | * @return mixed |
| 1127 | 1058 | */ |
| 1128 | 1059 | function findLast() { |
@@ -1160,8 +1091,6 @@ discard block |
||
| 1160 | 1091 | * @signature a -> [a] -> Number |
| 1161 | 1092 | * @signature v -> {k: v} -> Maybe(k) |
| 1162 | 1093 | * @signature String -> String -> Number |
| 1163 | - * @param mixed $item |
|
| 1164 | - * @param array $list |
|
| 1165 | 1094 | * @return int |
| 1166 | 1095 | */ |
| 1167 | 1096 | function indexOf() { |
@@ -1200,8 +1129,6 @@ discard block |
||
| 1200 | 1129 | * @signature a -> [a] -> Number |
| 1201 | 1130 | * @signature v -> {k: v} -> Maybe(k) |
| 1202 | 1131 | * @signature String -> String -> Number |
| 1203 | - * @param mixed $item |
|
| 1204 | - * @param array $list |
|
| 1205 | 1132 | * @return int |
| 1206 | 1133 | */ |
| 1207 | 1134 | function lastIndexOf() { |
@@ -1235,8 +1162,6 @@ discard block |
||
| 1235 | 1162 | * |
| 1236 | 1163 | * @stream |
| 1237 | 1164 | * @signature (a -> a -> Boolean) -> [a] -> [a] |
| 1238 | - * @param callable $areEqual |
|
| 1239 | - * @param array $list |
|
| 1240 | 1165 | * @return array |
| 1241 | 1166 | */ |
| 1242 | 1167 | function uniqueBy() { |
@@ -1273,7 +1198,6 @@ discard block |
||
| 1273 | 1198 | * |
| 1274 | 1199 | * @stream |
| 1275 | 1200 | * @signature [a] -> [a] |
| 1276 | - * @param array $list |
|
| 1277 | 1201 | * @return array |
| 1278 | 1202 | */ |
| 1279 | 1203 | function unique() { |
@@ -1306,8 +1230,6 @@ discard block |
||
| 1306 | 1230 | * |
| 1307 | 1231 | * @stream |
| 1308 | 1232 | * @signature (a -> String) -> [a] -> {String: a} |
| 1309 | - * @param callable $fn |
|
| 1310 | - * @param array $list |
|
| 1311 | 1233 | * @return array |
| 1312 | 1234 | */ |
| 1313 | 1235 | function groupBy() { |
@@ -1337,8 +1259,6 @@ discard block |
||
| 1337 | 1259 | * |
| 1338 | 1260 | * @stream |
| 1339 | 1261 | * @signature [a] -> [b] -> [[a,b]] |
| 1340 | - * @param array $list1 |
|
| 1341 | - * @param array $list2 |
|
| 1342 | 1262 | * @return array |
| 1343 | 1263 | */ |
| 1344 | 1264 | function pairsFrom() { |
@@ -1383,8 +1303,6 @@ discard block |
||
| 1383 | 1303 | * |
| 1384 | 1304 | * @stream |
| 1385 | 1305 | * @signature (a -> a -> Boolean) -> [a] -> [a] |
| 1386 | - * @param callable $compare |
|
| 1387 | - * @param array $list |
|
| 1388 | 1306 | * @return array |
| 1389 | 1307 | */ |
| 1390 | 1308 | function sort() { |
@@ -73,35 +73,35 @@ discard block |
||
| 73 | 73 | function filter() { |
| 74 | 74 | static $filter = false; |
| 75 | 75 | $filter = $filter ?: curry(function(callable $fn, $list) { |
| 76 | - $isArray = is_array($list); |
|
| 77 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 76 | + $isArray = is_array($list); |
|
| 77 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 78 | 78 | |
| 79 | - $result = $isArray ? [] |
|
| 80 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
| 81 | - : new \ArrayObject()); |
|
| 79 | + $result = $isArray ? [] |
|
| 80 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
| 81 | + : new \ArrayObject()); |
|
| 82 | 82 | |
| 83 | - if ($isArray) |
|
| 84 | - { |
|
| 85 | - foreach ($list as $item) { |
|
| 86 | - if ($fn($item)) |
|
| 87 | - $result[] = $item; |
|
| 88 | - } |
|
| 89 | - return $result; |
|
| 90 | - } |
|
| 83 | + if ($isArray) |
|
| 84 | + { |
|
| 85 | + foreach ($list as $item) { |
|
| 86 | + if ($fn($item)) |
|
| 87 | + $result[] = $item; |
|
| 88 | + } |
|
| 89 | + return $result; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return _iterable_reduce( |
|
| 93 | - _make_filterer($isObjectStorage ? |
|
| 94 | - function(\ArrayAccess $xs, $value) { |
|
| 95 | - $xs->offsetSet($value); |
|
| 96 | - } : |
|
| 97 | - function(\ArrayObject $xs, $value) { |
|
| 98 | - $xs->append($value); |
|
| 99 | - }, |
|
| 100 | - $fn |
|
| 101 | - ), |
|
| 102 | - $result, |
|
| 103 | - $isObjectStorage ? $list : $list->getIterator() |
|
| 104 | - ); |
|
| 92 | + return _iterable_reduce( |
|
| 93 | + _make_filterer($isObjectStorage ? |
|
| 94 | + function(\ArrayAccess $xs, $value) { |
|
| 95 | + $xs->offsetSet($value); |
|
| 96 | + } : |
|
| 97 | + function(\ArrayObject $xs, $value) { |
|
| 98 | + $xs->append($value); |
|
| 99 | + }, |
|
| 100 | + $fn |
|
| 101 | + ), |
|
| 102 | + $result, |
|
| 103 | + $isObjectStorage ? $list : $list->getIterator() |
|
| 104 | + ); |
|
| 105 | 105 | }); |
| 106 | 106 | return _apply($filter, func_get_args()); |
| 107 | 107 | } |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * @return \Closure |
| 114 | 114 | */ |
| 115 | 115 | function _make_filterer (callable $append, callable $predicate) { |
| 116 | - return function ($acc, ...$entry) use ($append, $predicate) { |
|
| 117 | - if ($predicate($entry[0])) { |
|
| 118 | - $append($acc, ...$entry); |
|
| 119 | - } |
|
| 120 | - return $acc; |
|
| 121 | - }; |
|
| 116 | + return function ($acc, ...$entry) use ($append, $predicate) { |
|
| 117 | + if ($predicate($entry[0])) { |
|
| 118 | + $append($acc, ...$entry); |
|
| 119 | + } |
|
| 120 | + return $acc; |
|
| 121 | + }; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -155,30 +155,30 @@ discard block |
||
| 155 | 155 | * @return array|\ArrayObject|\SplObjectStorage|callable |
| 156 | 156 | */ |
| 157 | 157 | function filter_values() { |
| 158 | - static $filter_values = false; |
|
| 158 | + static $filter_values = false; |
|
| 159 | 159 | $filter_values = $filter_values ?: curry(function(callable $predicate, $list) { |
| 160 | - $isArray = is_array($list); |
|
| 161 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 160 | + $isArray = is_array($list); |
|
| 161 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 162 | 162 | |
| 163 | - $result = $isArray ? [] |
|
| 164 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
| 165 | - : new \ArrayObject()); |
|
| 163 | + $result = $isArray ? [] |
|
| 164 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
| 165 | + : new \ArrayObject()); |
|
| 166 | 166 | |
| 167 | - return _iterable_reduce( |
|
| 168 | - _make_filterer($isArray ? |
|
| 169 | - function(array &$xs, $value, $key) { |
|
| 170 | - $xs[$key] = $value; |
|
| 171 | - } : |
|
| 172 | - function(\ArrayAccess $xs, $value, $key) { |
|
| 173 | - $xs->offsetSet($key, $value); |
|
| 174 | - }, |
|
| 175 | - $predicate |
|
| 176 | - ), |
|
| 177 | - $result, |
|
| 178 | - $isArray ? new \ArrayIterator($list) |
|
| 179 | - : ($isObjectStorage ? new _IteratorAdapter($list) |
|
| 180 | - : $list->getIterator()) |
|
| 181 | - ); |
|
| 167 | + return _iterable_reduce( |
|
| 168 | + _make_filterer($isArray ? |
|
| 169 | + function(array &$xs, $value, $key) { |
|
| 170 | + $xs[$key] = $value; |
|
| 171 | + } : |
|
| 172 | + function(\ArrayAccess $xs, $value, $key) { |
|
| 173 | + $xs->offsetSet($key, $value); |
|
| 174 | + }, |
|
| 175 | + $predicate |
|
| 176 | + ), |
|
| 177 | + $result, |
|
| 178 | + $isArray ? new \ArrayIterator($list) |
|
| 179 | + : ($isObjectStorage ? new _IteratorAdapter($list) |
|
| 180 | + : $list->getIterator()) |
|
| 181 | + ); |
|
| 182 | 182 | }); |
| 183 | 183 | return _apply($filter_values, func_get_args()); |
| 184 | 184 | } |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param callable $predicate the filter function |
| 113 | 113 | * @return \Closure |
| 114 | 114 | */ |
| 115 | -function _make_filterer (callable $append, callable $predicate) { |
|
| 116 | - return function ($acc, ...$entry) use ($append, $predicate) { |
|
| 115 | +function _make_filterer(callable $append, callable $predicate) { |
|
| 116 | + return function($acc, ...$entry) use ($append, $predicate) { |
|
| 117 | 117 | if ($predicate($entry[0])) { |
| 118 | 118 | $append($acc, ...$entry); |
| 119 | 119 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | function reduce() { |
| 204 | 204 | static $reduce = false; |
| 205 | - $reduce = $reduce ?: curry(function($fn, $initial, $list){ |
|
| 205 | + $reduce = $reduce ?: curry(function($fn, $initial, $list) { |
|
| 206 | 206 | return array_reduce($list, $fn, $initial); |
| 207 | 207 | }); |
| 208 | 208 | return _apply($reduce, func_get_args()); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | function each() { |
| 231 | 231 | static $each = false; |
| 232 | - $each = $each ?: curry(function($fn, $list){ |
|
| 232 | + $each = $each ?: curry(function($fn, $list) { |
|
| 233 | 233 | foreach ($list as $item) { |
| 234 | 234 | $fn($item); |
| 235 | 235 | } |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | * @param array|string $list |
| 280 | 280 | * @return mixed |
| 281 | 281 | */ |
| 282 | -function last () { |
|
| 282 | +function last() { |
|
| 283 | 283 | static $last = false; |
| 284 | 284 | $last = $last ?: curry(function($list) { |
| 285 | - if(is_string($list)) |
|
| 285 | + if (is_string($list)) |
|
| 286 | 286 | return substr($list, -1); |
| 287 | 287 | $size = count($list); |
| 288 | 288 | return ($size > 0) |
@@ -309,10 +309,10 @@ discard block |
||
| 309 | 309 | * @param array|string $list |
| 310 | 310 | * @return array |
| 311 | 311 | */ |
| 312 | -function init () { |
|
| 312 | +function init() { |
|
| 313 | 313 | static $init = false; |
| 314 | 314 | $init = $init ?: curry(function($list) { |
| 315 | - if(is_string($list)) { |
|
| 315 | + if (is_string($list)) { |
|
| 316 | 316 | $size = strlen($list); |
| 317 | 317 | return ($size > 1) |
| 318 | 318 | ? substr($list, 0, $size - 1) |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | * @param array|string $list |
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | -function tail () { |
|
| 346 | +function tail() { |
|
| 347 | 347 | static $tail = false; |
| 348 | 348 | $tail = $tail ?: curry(function($list) { |
| 349 | - if(is_string($list)) |
|
| 349 | + if (is_string($list)) |
|
| 350 | 350 | return (strlen($list) > 1) |
| 351 | 351 | ? substr($list, 1) |
| 352 | 352 | : ''; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @param array|string $list |
| 372 | 372 | * @return array |
| 373 | 373 | */ |
| 374 | -function reverse () { |
|
| 374 | +function reverse() { |
|
| 375 | 375 | static $reverse = false; |
| 376 | 376 | $reverse = $reverse ?: curry(function($list) { |
| 377 | 377 | return is_string($list) |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | static $allSatisfies = false; |
| 425 | 425 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
| 426 | 426 | foreach ($list as $item) { |
| 427 | - if (! $predicate($item)) |
|
| 427 | + if (!$predicate($item)) |
|
| 428 | 428 | return false; |
| 429 | 429 | } |
| 430 | 430 | return true; |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | function append() { |
| 602 | 602 | static $append = false; |
| 603 | - $append = $append ?: curry(function ($item, $list) { |
|
| 603 | + $append = $append ?: curry(function($item, $list) { |
|
| 604 | 604 | return is_string($list) |
| 605 | 605 | ? $list . $item |
| 606 | 606 | : array_merge($list, [$item]); |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | */ |
| 627 | 627 | function prepend() { |
| 628 | 628 | static $prepend = false; |
| 629 | - $prepend = $prepend ?: curry(function ($item, $list) { |
|
| 629 | + $prepend = $prepend ?: curry(function($item, $list) { |
|
| 630 | 630 | return is_string($list) |
| 631 | 631 | ? $item . $list |
| 632 | 632 | : array_merge([$item], $list); |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | $length = length($list); |
| 662 | 662 | if ($count > $length || $count < -$length) |
| 663 | 663 | return $list; |
| 664 | - if(is_string($list)) { |
|
| 664 | + if (is_string($list)) { |
|
| 665 | 665 | return ($count >= 0) |
| 666 | 666 | ? substr($list, 0, $count) |
| 667 | 667 | : substr($list, $count); |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | $count = ($count > 0) |
| 813 | 813 | ? $count - $length |
| 814 | 814 | : $count + $length; |
| 815 | - if(is_string($list)) { |
|
| 815 | + if (is_string($list)) { |
|
| 816 | 816 | return ($count >= 0) |
| 817 | 817 | ? substr($list, 0, $count) |
| 818 | 818 | : substr($list, $count); |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | $indexOf = $indexOf ?: curry(function($item, $list) { |
| 1170 | 1170 | if (is_string($list)) { |
| 1171 | 1171 | $index = strpos($list, $item); |
| 1172 | - return $index === false ? -1 : $index; |
|
| 1172 | + return $index === false ? - 1 : $index; |
|
| 1173 | 1173 | } |
| 1174 | 1174 | $list = (array) $list; |
| 1175 | 1175 | $index = 0; |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | return $keys[$index]; |
| 1181 | 1181 | $index ++; |
| 1182 | 1182 | } |
| 1183 | - return -1; |
|
| 1183 | + return - 1; |
|
| 1184 | 1184 | }); |
| 1185 | 1185 | return _apply($indexOf, func_get_args()); |
| 1186 | 1186 | } |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | $lastIndexOf = $lastIndexOf ?: curry(function($item, $list) { |
| 1210 | 1210 | if (is_string($list)) { |
| 1211 | 1211 | $index = strrpos($list, $item); |
| 1212 | - return $index === false ? -1 : $index; |
|
| 1212 | + return $index === false ? - 1 : $index; |
|
| 1213 | 1213 | } |
| 1214 | 1214 | $list = (array) $list; |
| 1215 | 1215 | $keys = array_keys($list); |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | return $keys[$index]; |
| 1220 | 1220 | $index --; |
| 1221 | 1221 | } |
| 1222 | - return -1; |
|
| 1222 | + return - 1; |
|
| 1223 | 1223 | }); |
| 1224 | 1224 | return _apply($lastIndexOf, func_get_args()); |
| 1225 | 1225 | } |
@@ -1254,7 +1254,7 @@ discard block |
||
| 1254 | 1254 | } |
| 1255 | 1255 | $index ++; |
| 1256 | 1256 | } |
| 1257 | - if (! $found) { |
|
| 1257 | + if (!$found) { |
|
| 1258 | 1258 | $result[$size] = $item; |
| 1259 | 1259 | $size ++; |
| 1260 | 1260 | } |
@@ -1314,9 +1314,9 @@ discard block |
||
| 1314 | 1314 | static $groupBy = false; |
| 1315 | 1315 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
| 1316 | 1316 | $result = []; |
| 1317 | - foreach($list as $item) { |
|
| 1317 | + foreach ($list as $item) { |
|
| 1318 | 1318 | $index = $fn($item); |
| 1319 | - if (! isset($result[$index])) |
|
| 1319 | + if (!isset($result[$index])) |
|
| 1320 | 1320 | $result[$index] = []; |
| 1321 | 1321 | $result[$index][] = $item; |
| 1322 | 1322 | } |
@@ -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); |
@@ -314,11 +314,11 @@ |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | function _iterable_reduce(callable $reducer, $acc, \Iterator $iterator) { |
| 317 | - $iterator->rewind(); |
|
| 318 | - while ($iterator->valid()) { |
|
| 319 | - $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
| 320 | - $iterator->next(); |
|
| 321 | - } |
|
| 322 | - return $acc; |
|
| 317 | + $iterator->rewind(); |
|
| 318 | + while ($iterator->valid()) { |
|
| 319 | + $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
| 320 | + $iterator->next(); |
|
| 321 | + } |
|
| 322 | + return $acc; |
|
| 323 | 323 | } |
| 324 | 324 | |
@@ -13,66 +13,66 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class _IteratorAdapter implements \Iterator |
| 15 | 15 | { |
| 16 | - private $objectStorage; |
|
| 16 | + private $objectStorage; |
|
| 17 | 17 | |
| 18 | - public function __construct(\SplObjectStorage $theObjectStorage) |
|
| 19 | - { |
|
| 20 | - $this->objectStorage = $theObjectStorage; |
|
| 21 | - } |
|
| 18 | + public function __construct(\SplObjectStorage $theObjectStorage) |
|
| 19 | + { |
|
| 20 | + $this->objectStorage = $theObjectStorage; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Return the current element |
|
| 25 | - * @link http://php.net/manual/en/iterator.current.php |
|
| 26 | - * @return mixed Can return any type. |
|
| 27 | - * @since 5.0.0 |
|
| 28 | - */ |
|
| 29 | - public function current() |
|
| 30 | - { |
|
| 31 | - return $this->objectStorage->getInfo(); |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Return the current element |
|
| 25 | + * @link http://php.net/manual/en/iterator.current.php |
|
| 26 | + * @return mixed Can return any type. |
|
| 27 | + * @since 5.0.0 |
|
| 28 | + */ |
|
| 29 | + public function current() |
|
| 30 | + { |
|
| 31 | + return $this->objectStorage->getInfo(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Move forward to next element |
|
| 36 | - * @link http://php.net/manual/en/iterator.next.php |
|
| 37 | - * @return void Any returned value is ignored. |
|
| 38 | - * @since 5.0.0 |
|
| 39 | - */ |
|
| 40 | - public function next() |
|
| 41 | - { |
|
| 42 | - return $this->objectStorage->next(); |
|
| 43 | - } |
|
| 34 | + /** |
|
| 35 | + * Move forward to next element |
|
| 36 | + * @link http://php.net/manual/en/iterator.next.php |
|
| 37 | + * @return void Any returned value is ignored. |
|
| 38 | + * @since 5.0.0 |
|
| 39 | + */ |
|
| 40 | + public function next() |
|
| 41 | + { |
|
| 42 | + return $this->objectStorage->next(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Return the key of the current element |
|
| 47 | - * @link http://php.net/manual/en/iterator.key.php |
|
| 48 | - * @return mixed scalar on success, or null on failure. |
|
| 49 | - * @since 5.0.0 |
|
| 50 | - */ |
|
| 51 | - public function key() |
|
| 52 | - { |
|
| 53 | - return $this->objectStorage->current(); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * Return the key of the current element |
|
| 47 | + * @link http://php.net/manual/en/iterator.key.php |
|
| 48 | + * @return mixed scalar on success, or null on failure. |
|
| 49 | + * @since 5.0.0 |
|
| 50 | + */ |
|
| 51 | + public function key() |
|
| 52 | + { |
|
| 53 | + return $this->objectStorage->current(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Checks if current position is valid |
|
| 58 | - * @link http://php.net/manual/en/iterator.valid.php |
|
| 59 | - * @return boolean The return value will be casted to boolean and then evaluated. |
|
| 60 | - * Returns true on success or false on failure. |
|
| 61 | - * @since 5.0.0 |
|
| 62 | - */ |
|
| 63 | - public function valid() |
|
| 64 | - { |
|
| 65 | - return $this->objectStorage->valid(); |
|
| 66 | - } |
|
| 56 | + /** |
|
| 57 | + * Checks if current position is valid |
|
| 58 | + * @link http://php.net/manual/en/iterator.valid.php |
|
| 59 | + * @return boolean The return value will be casted to boolean and then evaluated. |
|
| 60 | + * Returns true on success or false on failure. |
|
| 61 | + * @since 5.0.0 |
|
| 62 | + */ |
|
| 63 | + public function valid() |
|
| 64 | + { |
|
| 65 | + return $this->objectStorage->valid(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Rewind the Iterator to the first element |
|
| 70 | - * @link http://php.net/manual/en/iterator.rewind.php |
|
| 71 | - * @return void Any returned value is ignored. |
|
| 72 | - * @since 5.0.0 |
|
| 73 | - */ |
|
| 74 | - public function rewind() |
|
| 75 | - { |
|
| 76 | - return $this->objectStorage->rewind(); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * Rewind the Iterator to the first element |
|
| 70 | + * @link http://php.net/manual/en/iterator.rewind.php |
|
| 71 | + * @return void Any returned value is ignored. |
|
| 72 | + * @since 5.0.0 |
|
| 73 | + */ |
|
| 74 | + public function rewind() |
|
| 75 | + { |
|
| 76 | + return $this->objectStorage->rewind(); |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |