| @@ 2247-2261 (lines=15) @@ | ||
| 2244 | * @psalm-return static<TKey,T> |
|
| 2245 | * @psalm-mutation-free |
|
| 2246 | */ |
|
| 2247 | public function each(\Closure $closure): self |
|
| 2248 | { |
|
| 2249 | // init |
|
| 2250 | $array = []; |
|
| 2251 | ||
| 2252 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2253 | $array[$key] = $closure($value, $key); |
|
| 2254 | } |
|
| 2255 | ||
| 2256 | return static::create( |
|
| 2257 | $array, |
|
| 2258 | $this->iteratorClass, |
|
| 2259 | false |
|
| 2260 | ); |
|
| 2261 | } |
|
| 2262 | ||
| 2263 | /** |
|
| 2264 | * Sets the internal iterator to the last element in the array and returns this element. |
|
| @@ 5165-5176 (lines=12) @@ | ||
| 5162 | * @psalm-return static<TKey,T> |
|
| 5163 | * @psalm-mutation-free |
|
| 5164 | */ |
|
| 5165 | public function reduce($callable, $initial = []): self |
|
| 5166 | { |
|
| 5167 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5168 | $initial = $callable($initial, $value, $key); |
|
| 5169 | } |
|
| 5170 | ||
| 5171 | return static::create( |
|
| 5172 | $initial, |
|
| 5173 | $this->iteratorClass, |
|
| 5174 | false |
|
| 5175 | ); |
|
| 5176 | } |
|
| 5177 | ||
| 5178 | /** |
|
| 5179 | * @param bool $unique |
|
| @@ 5250-5266 (lines=17) @@ | ||
| 5247 | * @psalm-return static<TKey,T> |
|
| 5248 | * @psalm-mutation-free |
|
| 5249 | */ |
|
| 5250 | public function reject(\Closure $closure): self |
|
| 5251 | { |
|
| 5252 | // init |
|
| 5253 | $filtered = []; |
|
| 5254 | ||
| 5255 | foreach ($this->getGenerator() as $key => $value) { |
|
| 5256 | if (!$closure($value, $key)) { |
|
| 5257 | $filtered[$key] = $value; |
|
| 5258 | } |
|
| 5259 | } |
|
| 5260 | ||
| 5261 | return static::create( |
|
| 5262 | $filtered, |
|
| 5263 | $this->iteratorClass, |
|
| 5264 | false |
|
| 5265 | ); |
|
| 5266 | } |
|
| 5267 | ||
| 5268 | /** |
|
| 5269 | * Remove a value from the current array (optional using dot-notation). |
|