@@ -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 |
@@ -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 | } |