* @template-implements ICollection */ class Collection extends ImmutableCollection implements ICollection { /** * @inheritDoc */ public function set (int|string $key, mixed $value): self { return $this->_set($key, $value); } /** * @inheritDoc */ public function merge (IImmutableCollection ...$collections): ICollection { return $this->_merge(...$collections); } /** * @inheritDoc */ public function add (mixed ...$values): self { return $this->_add(...$values); } /** * @inheritDoc */ public function addCollection (IImmutableCollection ...$collections): ICollection { return $this->_addCollection(...$collections); } /** * @inheritDoc */ public function prepend (mixed ...$values): ICollection { array_unshift($this->elements, ...$values); return $this; } /** * @inheritDoc */ public function prependCollection (IImmutableCollection ...$collections): ICollection { $prepend = array_merge( ...array_map( function (IImmutableCollection $collection): array { return $collection->values()->toArray(); }, $collections ) ); return $this->prepend(...$prepend); } /** * @inheritDoc */ public function clear (): self { $this->_initialize(); return $this; } /** * @inheritDoc */ public function remove (int|string $key): self { unset($this->elements[$this->_normalizeKey($key)]); return $this; } /** * @inheritDoc */ public function removeValue (mixed $value, bool $strict = false): self { foreach ($this->elements as $currentKey => $currentValue) { if (($strict && $value === $currentValue) || (!$strict && $value == $currentValue)) { unset($this->elements[$currentKey]); } } return $this; } /** * @inheritDoc */ public function offsetSet (mixed $offset, mixed $value): void { $this->set($offset, $value); } /** * @inheritDoc */ public function offsetUnset (mixed $offset): void { $this->remove($offset); } }