Skip to content

Loading…

DCOM-17: Add Collection::slice($offset, $length) #471

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user @beberlei:

Since we are still at a point were bc breaks are potentially not so harming:

We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

/****
 * Extract 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.
 * 
 * @param int $offset
 * @param int $length
 * @return array
 */
public function slice($offset, $length = null);

The ArrayCollection implement would be:

public function slice($offset, $length = null);
{
    return array*slice($this->*elements, $offset, $length, true); // preserve keys
}
@doctrinebot

Comment created by @beberlei:

Updated preserve paragraph

@doctrinebot

Comment created by @beberlei:

Implemented

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by jpieper:

Is there any reason why slice() returns an array although methods like filter() and map() return an instance of Doctrine\Common\Collections\ArrayCollection?

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0.0-RC1 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.