| @@ 2331-2345 (lines=15) @@ | ||
| 2328 | * @phpstan-return static<TKey,T> |
|
| 2329 | * @psalm-mutation-free |
|
| 2330 | */ |
|
| 2331 | public function each(\Closure $closure): self |
|
| 2332 | { |
|
| 2333 | // init |
|
| 2334 | $array = []; |
|
| 2335 | ||
| 2336 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2337 | $array[$key] = $closure($value, $key); |
|
| 2338 | } |
|
| 2339 | ||
| 2340 | return static::create( |
|
| 2341 | $array, |
|
| 2342 | $this->iteratorClass, |
|
| 2343 | false |
|
| 2344 | ); |
|
| 2345 | } |
|
| 2346 | ||
| 2347 | /** |
|
| 2348 | * Sets the internal iterator to the last element in the array and returns this element. |
|
| @@ 5354-5365 (lines=12) @@ | ||
| 5351 | * @phpstan-return static<TKey,T2> |
|
| 5352 | * @psalm-mutation-free |
|
| 5353 | */ |
|
| 5354 | public function reduce($callable, $initial = []): self |
|
| 5355 | { |
|
| 5356 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5357 | $initial = $callable($initial, $value, $key); |
|
| 5358 | } |
|
| 5359 | ||
| 5360 | return static::create( |
|
| 5361 | $initial, |
|
| 5362 | $this->iteratorClass, |
|
| 5363 | false |
|
| 5364 | ); |
|
| 5365 | } |
|
| 5366 | ||
| 5367 | /** |
|
| 5368 | * @param bool $unique |
|
| @@ 5440-5456 (lines=17) @@ | ||
| 5437 | * @phpstan-return static<TKey,T> |
|
| 5438 | * @psalm-mutation-free |
|
| 5439 | */ |
|
| 5440 | public function reject(\Closure $closure): self |
|
| 5441 | { |
|
| 5442 | // init |
|
| 5443 | $filtered = []; |
|
| 5444 | ||
| 5445 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5446 | if (!$closure($value, $key)) { |
|
| 5447 | $filtered[$key] = $value; |
|
| 5448 | } |
|
| 5449 | } |
|
| 5450 | ||
| 5451 | return static::create( |
|
| 5452 | $filtered, |
|
| 5453 | $this->iteratorClass, |
|
| 5454 | false |
|
| 5455 | ); |
|
| 5456 | } |
|
| 5457 | ||
| 5458 | /** |
|
| 5459 | * Remove a value from the current array (optional using dot-notation). |
|