| @@ 2298-2312 (lines=15) @@ | ||
| 2295 | * @psalm-return static<TKey,T> |
|
| 2296 | * @psalm-mutation-free |
|
| 2297 | */ |
|
| 2298 | public function each(\Closure $closure): self |
|
| 2299 | { |
|
| 2300 | // init |
|
| 2301 | $array = []; |
|
| 2302 | ||
| 2303 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2304 | $array[$key] = $closure($value, $key); |
|
| 2305 | } |
|
| 2306 | ||
| 2307 | return static::create( |
|
| 2308 | $array, |
|
| 2309 | $this->iteratorClass, |
|
| 2310 | false |
|
| 2311 | ); |
|
| 2312 | } |
|
| 2313 | ||
| 2314 | /** |
|
| 2315 | * Sets the internal iterator to the last element in the array and returns this element. |
|
| @@ 5264-5275 (lines=12) @@ | ||
| 5261 | * @psalm-return static<TKey,T> |
|
| 5262 | * @psalm-mutation-free |
|
| 5263 | */ |
|
| 5264 | public function reduce($callable, $initial = []): self |
|
| 5265 | { |
|
| 5266 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5267 | $initial = $callable($initial, $value, $key); |
|
| 5268 | } |
|
| 5269 | ||
| 5270 | return static::create( |
|
| 5271 | $initial, |
|
| 5272 | $this->iteratorClass, |
|
| 5273 | false |
|
| 5274 | ); |
|
| 5275 | } |
|
| 5276 | ||
| 5277 | /** |
|
| 5278 | * @param bool $unique |
|
| @@ 5349-5365 (lines=17) @@ | ||
| 5346 | * @psalm-return static<TKey,T> |
|
| 5347 | * @psalm-mutation-free |
|
| 5348 | */ |
|
| 5349 | public function reject(\Closure $closure): self |
|
| 5350 | { |
|
| 5351 | // init |
|
| 5352 | $filtered = []; |
|
| 5353 | ||
| 5354 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5355 | if (!$closure($value, $key)) { |
|
| 5356 | $filtered[$key] = $value; |
|
| 5357 | } |
|
| 5358 | } |
|
| 5359 | ||
| 5360 | return static::create( |
|
| 5361 | $filtered, |
|
| 5362 | $this->iteratorClass, |
|
| 5363 | false |
|
| 5364 | ); |
|
| 5365 | } |
|
| 5366 | ||
| 5367 | /** |
|
| 5368 | * Remove a value from the current array (optional using dot-notation). |
|