@@ 2350-2364 (lines=15) @@ | ||
2347 | * @phpstan-return static<TKey,T> |
|
2348 | * @psalm-mutation-free |
|
2349 | */ |
|
2350 | public function each(\Closure $closure): self |
|
2351 | { |
|
2352 | // init |
|
2353 | $array = []; |
|
2354 | ||
2355 | foreach ($this->getGenerator() as $key => $value) { |
|
2356 | $array[$key] = $closure($value, $key); |
|
2357 | } |
|
2358 | ||
2359 | return static::create( |
|
2360 | $array, |
|
2361 | $this->iteratorClass, |
|
2362 | false |
|
2363 | ); |
|
2364 | } |
|
2365 | ||
2366 | /** |
|
2367 | * Sets the internal iterator to the last element in the array and returns this element. |
|
@@ 5374-5388 (lines=15) @@ | ||
5371 | * @phpstan-return static<TKey,T2> |
|
5372 | * @psalm-mutation-free |
|
5373 | */ |
|
5374 | public function reduce($callable, $initial = []): self |
|
5375 | { |
|
5376 | foreach ($this->getGenerator() as $key => $value) { |
|
5377 | $initial = $callable($initial, $value, $key); |
|
5378 | } |
|
5379 | ||
5380 | /** @var static<TKey,T2> $return - help for phpstan */ |
|
5381 | $return = static::create( |
|
5382 | $initial, |
|
5383 | $this->iteratorClass, |
|
5384 | false |
|
5385 | ); |
|
5386 | ||
5387 | return $return; |
|
5388 | } |
|
5389 | ||
5390 | /** |
|
5391 | * @param bool $unique |
|
@@ 5463-5479 (lines=17) @@ | ||
5460 | * @phpstan-return static<TKey,T> |
|
5461 | * @psalm-mutation-free |
|
5462 | */ |
|
5463 | public function reject(\Closure $closure): self |
|
5464 | { |
|
5465 | // init |
|
5466 | $filtered = []; |
|
5467 | ||
5468 | foreach ($this->getGenerator() as $key => $value) { |
|
5469 | if (!$closure($value, $key)) { |
|
5470 | $filtered[$key] = $value; |
|
5471 | } |
|
5472 | } |
|
5473 | ||
5474 | return static::create( |
|
5475 | $filtered, |
|
5476 | $this->iteratorClass, |
|
5477 | false |
|
5478 | ); |
|
5479 | } |
|
5480 | ||
5481 | /** |
|
5482 | * Remove a value from the current array (optional using dot-notation). |