Skip to content

Commit

Permalink
walk()
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Jan 17, 2025
1 parent 3302de1 commit 9ea4a19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Discord/Helpers/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function find(callable $callback);
public function clear(): void;
public function slice(int $offset, ?int $length, bool $preserve_keys = false);
public function sort(callable|int|null $callback);
public function walk(callable $callback, mixed $arg);
public function reduce(callable $callback, $initial = null);
public function map(callable $callback);
public function merge($collection): self;
Expand Down
17 changes: 17 additions & 0 deletions src/Discord/Helpers/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ public function sort(callable|int|null $callback)
return new Collection($items, $this->discrim, $this->class);
}

/**
* Applies the given callback function to each item in the collection.
*
* @param callable $callback
* @param mixed $arg
*
* @return CollectionInterface
*/
public function walk(callable $callback, mixed $arg)
{
$items = $this->items;

array_walk($items, $callback, $arg);

return new Collection($items, $this->discrim, $this->class);
}

/**
* Reduces the collection to a single value using a callback function.
*
Expand Down

0 comments on commit 9ea4a19

Please sign in to comment.