Completed
Pull Request — master (#6)
by
unknown
03:41 queued 01:28
created
src/Internal/_functions.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -314,11 +314,11 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Internal/_IteratorAdapter.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -13,66 +13,66 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/list.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -73,35 +73,35 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +93 added lines, -61 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.