|
|
@ -5,50 +5,44 @@ namespace jrosset\Collections;
|
|
|
|
use ArrayIterator;
|
|
|
|
use ArrayIterator;
|
|
|
|
use Closure;
|
|
|
|
use Closure;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use JsonException;
|
|
|
|
use OutOfBoundsException;
|
|
|
|
use Traversable;
|
|
|
|
use Traversable;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* An immutable collection
|
|
|
|
* An immutable collection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @psalm-template TKey of array-key
|
|
|
|
* @template TKey of array-key
|
|
|
|
* @template-covariant TValue
|
|
|
|
* @template TValue
|
|
|
|
* @template-implements IImmutableCollection<TKey, TValue>
|
|
|
|
*
|
|
|
|
|
|
|
|
* @implements IImmutableCollection<TKey, TValue>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class ImmutableCollection implements IImmutableCollection {
|
|
|
|
class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @var array The internal array of elements
|
|
|
|
* @var array<TKey, TValue> The internal array of elements
|
|
|
|
* @psalm-var array<TKey, TValue>
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @internal
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected array $elements;
|
|
|
|
protected array $elements;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initialise a new collection
|
|
|
|
* Initialise a new collection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array|Traversable|null $other The initial values
|
|
|
|
* @param iterable|null $other The initial values
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param array<TKey, TValue>|Traversable<TKey, TValue>|null
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException If the initial values aren't valid
|
|
|
|
* @throws InvalidArgumentException If the initial values aren't valid
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct ($other = null) {
|
|
|
|
public function __construct (?iterable $other = null) {
|
|
|
|
$this->_initialize($other);
|
|
|
|
$this->_initialize($other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initialise the internals elements
|
|
|
|
* Initialise the internals elements
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array|Traversable|null $other The initial values
|
|
|
|
* @param iterable|null $other The initial values
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param array<TKey, TValue>|Traversable<TKey, TValue>|null
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException If the initial values aren't valid
|
|
|
|
* @throws InvalidArgumentException If the initial values aren't valid
|
|
|
|
* @internal
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _initialize ($other = null) {
|
|
|
|
protected function _initialize (?iterable $other = null): void {
|
|
|
|
$this->elements = [];
|
|
|
|
$this->elements = [];
|
|
|
|
if ($other !== null) {
|
|
|
|
if ($other !== null) {
|
|
|
|
if (!is_array($other) && !$other instanceof Traversable) {
|
|
|
|
if (!is_array($other) && !$other instanceof Traversable) {
|
|
|
@ -63,17 +57,16 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Internally set a value to a key
|
|
|
|
* Internally set a value to a key
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array-key $key The key
|
|
|
|
* @param TKey $key The key
|
|
|
|
* @param mixed $value The value
|
|
|
|
* @param TValue $value The value
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TKey $key
|
|
|
|
|
|
|
|
* @psalm-param TValue $value
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* @noinspection PhpMissingReturnTypeInspection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _set ($key, $value): self {
|
|
|
|
protected function _set ($key, $value) {
|
|
|
|
$this->elements[$this->_normalizeKey($key)] = $value;
|
|
|
|
$this->elements[$this->_normalizeKey($key)] = $value;
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,8 +76,12 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
* @param IImmutableCollection ...$collections The collections to merge
|
|
|
|
* @param IImmutableCollection ...$collections The collections to merge
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @internal
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @noinspection PhpMissingReturnTypeInspection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _merge (IImmutableCollection ...$collections): self {
|
|
|
|
protected function _merge (IImmutableCollection ...$collections) {
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
foreach ($collection as $key => $value) {
|
|
|
|
foreach ($collection as $key => $value) {
|
|
|
|
$this->_set($key, $value);
|
|
|
|
$this->_set($key, $value);
|
|
|
@ -95,15 +92,15 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Internally add a value
|
|
|
|
* Internally add a value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed ...$values The value
|
|
|
|
* @param TValue ...$values The value
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TValue ...$value
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* @noinspection PhpMissingReturnTypeInspection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _add (...$values): self {
|
|
|
|
protected function _add (...$values) {
|
|
|
|
foreach ($values as $value) {
|
|
|
|
foreach ($values as $value) {
|
|
|
|
$this->elements[] = $value;
|
|
|
|
$this->elements[] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,9 +111,11 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param IImmutableCollection ...$collections The collections to add
|
|
|
|
* @param IImmutableCollection ...$collections The collections to add
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @noinspection PhpMissingReturnTypeInspection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _addCollection (IImmutableCollection ...$collections): self {
|
|
|
|
protected function _addCollection (IImmutableCollection ...$collections) {
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
foreach ($collection as $value) {
|
|
|
|
foreach ($collection as $value) {
|
|
|
|
$this->_add($value);
|
|
|
|
$this->_add($value);
|
|
|
@ -127,21 +126,32 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Normalize a key
|
|
|
|
* Normalize a key
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array-key $key The key to normalize
|
|
|
|
* @param TKey $key The key to normalize
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TKey $key
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return array-key The normalized key
|
|
|
|
* @return TKey The normalized key
|
|
|
|
* @psalm-return TKey
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _normalizeKey ($key) {
|
|
|
|
protected function _normalizeKey ($key) {
|
|
|
|
return $key;
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Vérifie un offset (≥ 0, < {@see static::count()})
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param int $offset L'offset à vérifier
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws OutOfBoundsException Si l'offset est invalide
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function _checkOffset (int $offset): void {
|
|
|
|
|
|
|
|
if ($offset < 0 || $offset >= $this->count()) {
|
|
|
|
|
|
|
|
throw new OutOfBoundsException('The offset must be between 0 and ' . ($this->count() - 1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getIterator () {
|
|
|
|
public function getIterator (): ArrayIterator {
|
|
|
|
return new ArrayIterator($this->elements);
|
|
|
|
return new ArrayIterator($this->elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -170,6 +180,16 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
throw new ImmutableException();
|
|
|
|
throw new ImmutableException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* List of properties to {@see https://www.php.net/manual/function.serialize.php serialize}
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return array[] List of properties to {@see https://www.php.net/manual/function.serialize.php serialize}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function __serialize (): array {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'elements' => $this->elements,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -222,6 +242,14 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
public function get ($key) {
|
|
|
|
public function get ($key) {
|
|
|
|
return $this->elements[$this->_normalizeKey($key)] ?? null;
|
|
|
|
return $this->elements[$this->_normalizeKey($key)] ?? null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getFromOffset (int $offset) {
|
|
|
|
|
|
|
|
$this->_checkOffset($offset);
|
|
|
|
|
|
|
|
return array_values($this->elements)[$offset];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -233,11 +261,46 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function keyFromOffset (int $offset) {
|
|
|
|
|
|
|
|
$this->_checkOffset($offset);
|
|
|
|
|
|
|
|
return array_keys($this->elements)[$offset];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function first () {
|
|
|
|
|
|
|
|
return $this->getFromOffset(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function firstKey () {
|
|
|
|
|
|
|
|
return $this->keyFromOffset(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function slice (int $offset, ?int $length = null): self {
|
|
|
|
public function last () {
|
|
|
|
|
|
|
|
return $this->getFromOffset($this->count() - 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function lastKey () {
|
|
|
|
|
|
|
|
return $this->keyFromOffset($this->count() - 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function slice (int $offset, ?int $length = null) {
|
|
|
|
|
|
|
|
$this->_checkOffset($offset);
|
|
|
|
|
|
|
|
|
|
|
|
$output = new static();
|
|
|
|
$output = new static();
|
|
|
|
|
|
|
|
|
|
|
|
$currentIndex = 0;
|
|
|
|
$currentIndex = 0;
|
|
|
@ -258,7 +321,7 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function filter (Closure $filter): self {
|
|
|
|
public function filter (Closure $filter) {
|
|
|
|
$output = new static();
|
|
|
|
$output = new static();
|
|
|
|
foreach ($this->elements as $key => $value) {
|
|
|
|
foreach ($this->elements as $key => $value) {
|
|
|
|
if (!$filter($key, $value)) {
|
|
|
|
if (!$filter($key, $value)) {
|
|
|
@ -271,7 +334,7 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function withoutEmpties (): self {
|
|
|
|
public function withoutEmpties () {
|
|
|
|
return $this->filter(function ($value) {
|
|
|
|
return $this->filter(function ($value) {
|
|
|
|
return empty($value);
|
|
|
|
return empty($value);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -279,14 +342,7 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function removeEmpties (): self {
|
|
|
|
public function map (Closure $process) {
|
|
|
|
$this->_initialize($this->withoutEmpties());
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function map (Closure $process): self {
|
|
|
|
|
|
|
|
$output = new static();
|
|
|
|
$output = new static();
|
|
|
|
foreach ($this->elements as $key => $value) {
|
|
|
|
foreach ($this->elements as $key => $value) {
|
|
|
|
$output->_set($key, $process($key, $value));
|
|
|
|
$output->_set($key, $process($key, $value));
|
|
|
@ -297,23 +353,71 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function keys (): self {
|
|
|
|
public function sort ($sorter = null) {
|
|
|
|
|
|
|
|
$elements = $this->toArray();
|
|
|
|
|
|
|
|
uasort($elements, self::_normalizeSorter($sorter));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new static($elements);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function sortByKey ($sorter) {
|
|
|
|
|
|
|
|
$elements = $this->toArray();
|
|
|
|
|
|
|
|
uksort($elements, self::_normalizeSorter($sorter));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new static($elements);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Normalize a sorter method
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param null|IComparator|Closure(TValue, TValue):int $sorter The sorting method ; Null if values are object implementing {@see IComparable}.
|
|
|
|
|
|
|
|
* <br>Return :
|
|
|
|
|
|
|
|
* <br>< 0 if value1 is before value2
|
|
|
|
|
|
|
|
* <br>= 0 if value1 equals value2
|
|
|
|
|
|
|
|
* <br>> 0 if value1 is after value2
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return Closure(TValue, TValue):int The normalized sorter method
|
|
|
|
|
|
|
|
* <br>Return :
|
|
|
|
|
|
|
|
* <br>< 0 if value1 is before value2
|
|
|
|
|
|
|
|
* <br>= 0 if value1 equals value2
|
|
|
|
|
|
|
|
* <br>> 0 if value1 is after value2
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static function _normalizeSorter ($sorter): Closure {
|
|
|
|
|
|
|
|
if ($sorter === null) {
|
|
|
|
|
|
|
|
return function (IComparable $value1, IComparable $value2): int {
|
|
|
|
|
|
|
|
return $value1->compareTo($value2);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
elseif ($sorter instanceof IComparator) {
|
|
|
|
|
|
|
|
return function ($value1, $value2) use ($sorter): int {
|
|
|
|
|
|
|
|
return $sorter->compare($value1, $value2);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return $sorter;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function keys (): IImmutableCollection {
|
|
|
|
return new static(array_keys($this->elements));
|
|
|
|
return new static(array_keys($this->elements));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function values (): self {
|
|
|
|
public function values () {
|
|
|
|
return new static(array_values($this->elements));
|
|
|
|
return new static(array_values($this->elements));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws JsonException
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function jsonSerialize () {
|
|
|
|
public function jsonSerialize () {
|
|
|
|
return json_encode($this->elements, JSON_THROW_ON_ERROR);
|
|
|
|
return $this->elements;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -325,14 +429,36 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function split (string $value, string $separator): self {
|
|
|
|
public static function split (string $value, string $separator) {
|
|
|
|
return new static (explode($separator, $value));
|
|
|
|
return new static (explode($separator, $value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function combineWith (IImmutableCollection ...$collections): IImmutableCollection {
|
|
|
|
public static function fill (int $size, $value) {
|
|
|
|
|
|
|
|
$keys = new ImmutableCollection();
|
|
|
|
|
|
|
|
for ($curr = 0; $curr < $size; $curr++) {
|
|
|
|
|
|
|
|
$keys->_add($curr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return static::fillWithKeys($keys, $value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static function fillWithKeys (IImmutableCollection $keys, $value) {
|
|
|
|
|
|
|
|
$collection = new static();
|
|
|
|
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
|
|
|
|
$collection->_set($key, $value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $collection;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function mergeWith (IImmutableCollection ...$collections) {
|
|
|
|
return (clone $this)->_merge(...$collections);
|
|
|
|
return (clone $this)->_merge(...$collections);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|