#81840Make ObjectStorage implement Doctrine\Common\Collections\Collection Interface
Description
The `doctrine/collections` package is already a implicit dependency (through `doctrine/common` -> `doctrine/dbal`) and contains the `ArrayCollection` class, which is the most basic type of collection which sits on an array.
This would enhance the ObjectStorage with some useful new capabilities, most notably:
/**
* Tests for the existence of an element that satisfies the given predicate.
*
* param Closure $p The predicate.
*
* return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
*/
public function exists(Closure $p);
/**
* Returns all the elements of this collection that satisfy the predicate p.
* The order of the elements is preserved.
*
* param Closure $p The predicate used for filtering.
*
* return Collection A collection with the results of the filter operation.
*/
public function filter(Closure $p);
/**
* Tests whether the given predicate p holds for all elements of this collection.
*
* param Closure $p The predicate.
*
* return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
*/
public function forAll(Closure $p);
/**
* Applies the given function to each element in the collection and returns
* a new collection with the elements returned by the function.
*
* param Closure $func
*
* return Collection
*/
public function map(Closure $func);
/**
* Partitions this collection in two collections according to a predicate.
* Keys are preserved in the resulting collections.
*
* param Closure $p The predicate on which to partition.
*
* return array An array with two elements. The first element contains the collection
* of elements where the predicate returned TRUE, the second element
* contains the collection of elements where the predicate returned FALSE.
*/
public function partition(Closure $p);
/**
* Extracts a slice of $length elements starting at position $offset from the Collection.
*
* If $length is null it returns all elements from $offset to the end of the Collection.
* Keys have to be preserved by this method. Calling this method will only return the
* selected slice and NOT change the elements contained in the collection slice is called on.
*
* param int $offset The offset to start from.
* param int|null $length The maximum number of elements to return, or null for no limit.
*
* @return array
*/
public function slice($offset, $length = null);
Implementing those methods would cut off a bunch of post-processing we do on ObjectStorages.
The Interface itself can be found here: https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/Collection.php
I have a draft implementation lined up and will push it to gerrit soon.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 4
-
Susanne Moog changed target version <span data-processor="relativetime" data-value="2018-01-28T14:28:50+00:00" > 01/28/18, 14:28 </span>
-
Christian Eßl changed category <span data-processor="relativetime" data-value="2019-10-01T18:17:19+00:00" > 10/01/19, 18:17 </span>
-
Alexander Schnitzler commented and changed status
NewAccepted target version <span data-processor="relativetime" data-value="2020-01-16T11:45:46+00:00" > 01/16/20, 11:45 </span> -
Benni Mack commented and changed status
AcceptedClosed <span data-processor="relativetime" data-value="2026-11-16T08:51:29+00:00" > 11/16/26, 08:51 </span>I will close this one in favor of #88613
I like the idea and have even more here. I want to replace the ObjectStorage completely. But that’s a different and more complex topic.