Skip to content

Commit

Permalink
insersect()
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Jan 17, 2025
1 parent cb0a8f3 commit 1b8f252
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/Discord/Helpers/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,35 @@ public function sort(callable|int|null $callback)
*
* @return CollectionInterface
*/
public function diff($array, ?callable $callback)
public function diff($items, ?callable $callback)
{
$array = $array instanceof CollectionInterface
? $array->toArray()
: $array;
$items = $items instanceof CollectionInterface
? $items->toArray()
: $items;

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

$callback && is_callable($callback)
? array_udiff_assoc($items, $array, $callback)
: array_diff($items, $array);
return new Collection($diff, $this->discrim, $this->class);
}

return new Collection($items, $this->discrim, $this->class);
/**
* Gets the intersection of the items.
*
* @param CollectionInterface|array $array
*
* @return CollectionInterface
*/
public function intersect($items)
{
$items = $items instanceof CollectionInterface
? $items->toArray()
: $items;

$diff = array_intersect($this->items, $items);

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

/**
Expand Down

0 comments on commit 1b8f252

Please sign in to comment.