Skip to content

Commit

Permalink
uintersect
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Jan 17, 2025
1 parent 1b8f252 commit 065d27d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Discord/Helpers/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ public function sort(callable|int|null $callback)
}

/**
* Computes the difference between the current collection and the given array.
* Gets the difference between the items.
*
* If a callback is provided and is callable, it uses `array_udiff_assoc` to compute the difference.
* Otherwise, it uses `array_diff`.
*
* @param CollectionInterface|array $array
* @param ?callable $callback
* @param ?callable $callback
*
* @return CollectionInterface
*/
Expand All @@ -358,17 +358,23 @@ public function diff($items, ?callable $callback)
/**
* Gets the intersection of the items.
*
* If a callback is provided and is callable, it uses `array_uintersect_assoc` to compute the intersection.
* Otherwise, it uses `array_intersect`.
*
* @param CollectionInterface|array $array
* @param ?callable $callback
*
* @return CollectionInterface
*/
public function intersect($items)
public function intersect($items, ?callable $callback)
{
$items = $items instanceof CollectionInterface
? $items->toArray()
: $items;

$diff = array_intersect($this->items, $items);
$diff = $callback && is_callable($callback)
? array_uintersect_assoc($this->items, $items, $callback)
: array_intersect($this->items, $items);

return new Collection($diff, $this->discrim, $this->class);
}
Expand Down

0 comments on commit 065d27d

Please sign in to comment.