| @@ 309-317 (lines=9) @@ | ||
| 306 | * |
|
| 307 | * @return $this |
|
| 308 | */ |
|
| 309 | public function transform(callable $callback) |
|
| 310 | { |
|
| 311 | $index = 0; |
|
| 312 | foreach ($this->items as $key => $value) { |
|
| 313 | $this->set($key, $callback($value, $key, $index++)); |
|
| 314 | } |
|
| 315 | ||
| 316 | return $this; |
|
| 317 | } |
|
| 318 | ||
| 319 | /** |
|
| 320 | * Filter and return a new Collection. |
|
| @@ 348-358 (lines=11) @@ | ||
| 345 | * |
|
| 346 | * @return $this |
|
| 347 | */ |
|
| 348 | public function prune(callable $callback) |
|
| 349 | { |
|
| 350 | $index = 0; |
|
| 351 | foreach ($this->items as $key => $value) { |
|
| 352 | if (!$callback($value, $key, $index++)) { |
|
| 353 | $this->remove($key); |
|
| 354 | } |
|
| 355 | } |
|
| 356 | ||
| 357 | return $this; |
|
| 358 | } |
|
| 359 | ||
| 360 | /** |
|
| 361 | * Combine and return a new Collection. |
|
| @@ 474-482 (lines=9) @@ | ||
| 471 | * |
|
| 472 | * @return $this |
|
| 473 | */ |
|
| 474 | public function each(callable $callback) |
|
| 475 | { |
|
| 476 | $index = 0; |
|
| 477 | foreach ($this->items as $key => $value) { |
|
| 478 | $callback($value, $key, $index++); |
|
| 479 | } |
|
| 480 | ||
| 481 | return $this; |
|
| 482 | } |
|
| 483 | ||
| 484 | /** |
|
| 485 | * Flip the keys and the values and return a new Collection. |
|
| @@ 96-104 (lines=9) @@ | ||
| 93 | /** |
|
| 94 | * {@inheritdoc} |
|
| 95 | */ |
|
| 96 | public function each(callable $callback) |
|
| 97 | { |
|
| 98 | $index = 0; |
|
| 99 | foreach ($this->items as $key => $value) { |
|
| 100 | $callback($value, $key, $index++); |
|
| 101 | } |
|
| 102 | ||
| 103 | return $this; |
|
| 104 | } |
|
| 105 | ||
| 106 | /** |
|
| 107 | * {@inheritdoc} |
|