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