| @@ 2256-2270 (lines=15) @@ | ||
| 2253 | * @psalm-return static<TKey,T> |
|
| 2254 | * @psalm-mutation-free |
|
| 2255 | */ |
|
| 2256 | public function each(\Closure $closure): self |
|
| 2257 | { |
|
| 2258 | // init |
|
| 2259 | $array = []; |
|
| 2260 | ||
| 2261 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2262 | $array[$key] = $closure($value, $key); |
|
| 2263 | } |
|
| 2264 | ||
| 2265 | return static::create( |
|
| 2266 | $array, |
|
| 2267 | $this->iteratorClass, |
|
| 2268 | false |
|
| 2269 | ); |
|
| 2270 | } |
|
| 2271 | ||
| 2272 | /** |
|
| 2273 | * Sets the internal iterator to the last element in the array and returns this element. |
|
| @@ 5182-5193 (lines=12) @@ | ||
| 5179 | * @psalm-return static<TKey,T> |
|
| 5180 | * @psalm-mutation-free |
|
| 5181 | */ |
|
| 5182 | public function reduce($callable, $initial = []): self |
|
| 5183 | { |
|
| 5184 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5185 | $initial = $callable($initial, $value, $key); |
|
| 5186 | } |
|
| 5187 | ||
| 5188 | return static::create( |
|
| 5189 | $initial, |
|
| 5190 | $this->iteratorClass, |
|
| 5191 | false |
|
| 5192 | ); |
|
| 5193 | } |
|
| 5194 | ||
| 5195 | /** |
|
| 5196 | * @param bool $unique |
|
| @@ 5267-5283 (lines=17) @@ | ||
| 5264 | * @psalm-return static<TKey,T> |
|
| 5265 | * @psalm-mutation-free |
|
| 5266 | */ |
|
| 5267 | public function reject(\Closure $closure): self |
|
| 5268 | { |
|
| 5269 | // init |
|
| 5270 | $filtered = []; |
|
| 5271 | ||
| 5272 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5273 | if (!$closure($value, $key)) { |
|
| 5274 | $filtered[$key] = $value; |
|
| 5275 | } |
|
| 5276 | } |
|
| 5277 | ||
| 5278 | return static::create( |
|
| 5279 | $filtered, |
|
| 5280 | $this->iteratorClass, |
|
| 5281 | false |
|
| 5282 | ); |
|
| 5283 | } |
|
| 5284 | ||
| 5285 | /** |
|
| 5286 | * Remove a value from the current array (optional using dot-notation). |
|