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