|
|
@ -12,11 +12,12 @@ use Throwable;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Interface for an immutable (read-only) collection
|
|
|
|
* Interface for an immutable (read-only) collection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @psalm-template TKey of array-key
|
|
|
|
* @template TKey of array-key
|
|
|
|
* @template-covariant TValue
|
|
|
|
* @template TValue
|
|
|
|
* @template-extends IteratorAggregate<TKey, TValue>
|
|
|
|
*
|
|
|
|
* @template-extends ArrayAccess<TKey, TValue>
|
|
|
|
* @implements IteratorAggregate<TKey, TValue>
|
|
|
|
* @template-extends IArrayCast<TKey, TValue>
|
|
|
|
* @implements ArrayAccess<TKey, TValue>
|
|
|
|
|
|
|
|
* @implements IArrayCast<TKey, TValue>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Countable, ArrayAccess, IArrayCast {
|
|
|
|
interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Countable, ArrayAccess, IArrayCast {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -29,48 +30,38 @@ interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Coun
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Checks if a key exists
|
|
|
|
* Checks if a key exists
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array-key $key The key
|
|
|
|
* @param TKey $key The key
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TKey $key
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return bool TRUE if the key exists, FALSE otherwise
|
|
|
|
* @return bool TRUE if the key exists, FALSE otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function exists (int|string $key): bool;
|
|
|
|
public function exists ($key): bool;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Checks if contains a value
|
|
|
|
* Checks if contains a value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $value The value
|
|
|
|
* @param TValue $value The value
|
|
|
|
* @param bool $strict Strict comparison ?
|
|
|
|
* @param bool $strict Strict comparison ?
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TValue $value
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return bool TRUE if the value exists, FALSE otherwise
|
|
|
|
* @return bool TRUE if the value exists, FALSE otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function contains (mixed $value, bool $strict = false): bool;
|
|
|
|
public function contains ($value, bool $strict = false): bool;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get the value of a key or null if not found
|
|
|
|
* Get the value of a key or null if not found
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array-key $key The key
|
|
|
|
* @param TKey $key The key
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @psalm-param TKey $key
|
|
|
|
* @return TValue|null The value
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return mixed The value
|
|
|
|
|
|
|
|
* @psalm-return TValue|null
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function get (int|string $key): mixed;
|
|
|
|
public function get ($key): mixed;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get the first key of a value or null if not found
|
|
|
|
* Get the first key of a value or null if not found
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $value The value
|
|
|
|
* @param TValue $value The value
|
|
|
|
* @param bool $strict Strict comparison ?
|
|
|
|
* @param bool $strict Strict comparison ?
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param TValue $value
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return array-key|null
|
|
|
|
* @return TKey|null
|
|
|
|
* @psalm-return TKey|null
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function key (mixed $value, bool $strict = false): int|string|null;
|
|
|
|
public function key ($value, bool $strict = false);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Extract a slice of the collection
|
|
|
|
* Extract a slice of the collection
|
|
|
@ -80,54 +71,39 @@ interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Coun
|
|
|
|
* @param int $offset The start offset
|
|
|
|
* @param int $offset The start offset
|
|
|
|
* @param int|null $length The maximum length. Null if until end of the collection
|
|
|
|
* @param int|null $length The maximum length. Null if until end of the collection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
* @psalm-return static<TKey, TValue>
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function slice (int $offset, ?int $length = null): self;
|
|
|
|
public function slice (int $offset, ?int $length = null): static;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get a collection of all elements that satisfy predicate $filter
|
|
|
|
* Get a collection of all elements that satisfy predicate $filter
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param Closure $filter The filtering predicate
|
|
|
|
* @param Closure(TKey, TValue):bool $filter The filtering predicate
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-param Closure(TKey, TValue):bool $filter
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The result collection
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
* @psalm-return static<TKey, TValue>
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function filter (Closure $filter): self;
|
|
|
|
public function filter (Closure $filter): static;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get a collection of all not empty elements
|
|
|
|
* Get a collection of all not empty elements
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Use {@see https://www.php.net/manual/function.empty.php empty} to check if element is empty or not
|
|
|
|
* Use {@see https://www.php.net/manual/function.empty.php empty} to check if element is empty or not
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The result collection
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function withoutEmpties (): self;
|
|
|
|
public function withoutEmpties (): static;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Remove all empty elements on current collection
|
|
|
|
* A new collection with <b>$process</b> applied on all elements
|
|
|
|
*
|
|
|
|
|
|
|
|
* Use {@see https://www.php.net/manual/function.empty.php empty} to check if element is empty or not
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function removeEmpties (): self;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* A new collection with $process applied on all elements
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @psalm-template TResultValue
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param Closure $process The process function to apply on each element
|
|
|
|
* @template TResultValue
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @psalm-param Closure(TKey, TValue): TResultValue $process
|
|
|
|
* @param Closure(TKey, TValue): TResultValue $process The process function to apply on each element
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
* @return static<TKey, TResultValue> The result collection
|
|
|
|
* @psalm-return static<TKey, TResultValue>
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function map (Closure $process): self;
|
|
|
|
public function map (Closure $process): static;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sort the elements (by value)
|
|
|
|
* Get a collection with the elements sorted (by value)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param null|IComparator|Closure(TValue, TValue):int $sorter The sorting method ; Null if values are object implementing {@see IComparable}.
|
|
|
|
* @param null|IComparator|Closure(TValue, TValue):int $sorter The sorting method ; Null if values are object implementing {@see IComparable}.
|
|
|
|
* <br>Return :
|
|
|
|
* <br>Return :
|
|
|
@ -135,22 +111,20 @@ interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Coun
|
|
|
|
* <br>= 0 if value1 equals value2
|
|
|
|
* <br>= 0 if value1 equals value2
|
|
|
|
* <br>> 0 if value1 is after value2
|
|
|
|
* <br>> 0 if value1 is after value2
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The sorted collection
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
* @psalm-return static<TKey, TValue>
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function sort (Closure|IComparator|null $sorter = null): static;
|
|
|
|
public function sort (Closure|IComparator|null $sorter = null): static;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sort the elements by key
|
|
|
|
* Get a collection with the elements sorted by key
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param IComparator|Closure(TKey, TKey):int $sorter The sorting method. Return :
|
|
|
|
* @param IComparator|Closure(TKey, TKey):int $sorter The sorting method. Return :
|
|
|
|
* <br>< 0 if key1 is before key2
|
|
|
|
* <br>< 0 if key1 is before key2
|
|
|
|
* <br>= 0 if key1 equals key2
|
|
|
|
* <br>= 0 if key1 equals key2
|
|
|
|
* <br>> 0 if key1 is after key2
|
|
|
|
* <br>> 0 if key1 is after key2
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The sorted collection
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
* @psalm-return static<TKey, TValue>
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -159,17 +133,15 @@ interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Coun
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The list of all keys
|
|
|
|
* The list of all keys
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The list of all keys
|
|
|
|
* @return IImmutableCollection<int, TKey> The list of all keys
|
|
|
|
* @psalm-return static<int, TKey>
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function keys (): self;
|
|
|
|
public function keys (): IImmutableCollection;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The list of all values
|
|
|
|
* The list of all values
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The list of all values
|
|
|
|
* @return static<int, TValue> The list of all values
|
|
|
|
* @psalm-return static<int, TValue>
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function values (): self;
|
|
|
|
public function values (): static;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Join all values with a separator
|
|
|
|
* Join all values with a separator
|
|
|
@ -185,16 +157,16 @@ interface IImmutableCollection extends IteratorAggregate, JsonSerializable, Coun
|
|
|
|
* @param string $value The value to split
|
|
|
|
* @param string $value The value to split
|
|
|
|
* @param string $separator The split separator
|
|
|
|
* @param string $separator The split separator
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
* @return static<int, string> The result collection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function split (string $value, string $separator): self;
|
|
|
|
public static function split (string $value, string $separator): static;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Combine the current collection with one or multiple other collections
|
|
|
|
* Merge the current collection with one or multiple collections
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param IImmutableCollection ...$collections The other collections to combine
|
|
|
|
* @param IImmutableCollection<TKey, TValue> ...$collections The other collections to merge
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return static The combined collection
|
|
|
|
* @return static<TKey, TValue> The result collection
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function combineWith (IImmutableCollection ...$collections): self;
|
|
|
|
public function mergeWith (IImmutableCollection ...$collections): static;
|
|
|
|
}
|
|
|
|
}
|