/** * Retains only the elements in this collection that are contained in the specified collection (optional operation). * @param CollectionInterface $collection * @return boolean */ public function retainAll(CollectionInterface $collection) { $iterator = $this->iterator(); $changed = false; while ($iterator->hasNext()) { if (!$collection->contains($iterator->next())) { $iterator->remove(); $changed = true; } } return $changed; }