| @@ 206-219 (lines=14) @@ | ||
| 203 | * @param \ArrayAccess|array $items |
|
| 204 | * @return static |
|
| 205 | */ |
|
| 206 | public function diff($items) |
|
| 207 | { |
|
| 208 | $diff = new static([], $this->model); |
|
| 209 | ||
| 210 | $dictionary = $this->getDictionary($items); |
|
| 211 | ||
| 212 | foreach ($this->items as $item) { |
|
| 213 | if (!isset($dictionary[(string) $item->getKey()])) { |
|
| 214 | $diff->add($item); |
|
| 215 | } |
|
| 216 | } |
|
| 217 | ||
| 218 | return $diff; |
|
| 219 | } |
|
| 220 | ||
| 221 | /** |
|
| 222 | * Intersect the collection with the given items. |
|
| @@ 227-240 (lines=14) @@ | ||
| 224 | * @param \ArrayAccess|array $items |
|
| 225 | * @return static |
|
| 226 | */ |
|
| 227 | public function intersect($items) |
|
| 228 | { |
|
| 229 | $intersect = new static([], $this->model); |
|
| 230 | ||
| 231 | $dictionary = $this->getDictionary($items); |
|
| 232 | ||
| 233 | foreach ($this->items as $item) { |
|
| 234 | if (isset($dictionary[(string) $item->getKey()])) { |
|
| 235 | $intersect->add($item); |
|
| 236 | } |
|
| 237 | } |
|
| 238 | ||
| 239 | return $intersect; |
|
| 240 | } |
|
| 241 | ||
| 242 | /** |
|
| 243 | * Return only unique items from the collection. |
|