Skip to content

Commit

Permalink
Making _unwrap() a method of the ColletionInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 10, 2015
1 parent 6c4e7ab commit 04675ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/Collection/CollectionInterface.php
Expand Up @@ -847,4 +847,13 @@ public function through(callable $handler);
* @return bool
*/
public function isEmpty();

/**
* Returns the closest nested iterator that can be safely traversed without
* losing any possible transformations. This is used mainly to remove empty
* IteratorIterator wrappers that can only slowdown the iteration process.
*
* @return \Iterator
*/
public function _unwrap();
}
10 changes: 4 additions & 6 deletions src/Collection/CollectionTrait.php
Expand Up @@ -316,10 +316,9 @@ public function first()
*/
public function append($items)
{
$items = $items instanceof Iterator ? $items : new Collection($items);
$list = new AppendIterator;
$list->append($this);
$list->append($items->_unwrap());
$list->append((new Collection($items))->_unwrap());
return new Collection($list);
}

Expand Down Expand Up @@ -540,13 +539,12 @@ public function isEmpty()
return iterator_count($this->take(1)) === 0;
}


/**
* Returns the closest nested iterator that can be safely traversed without
* losing any possible transformations.
* {@inheritDoc}
*
* @return \Iterator
*/
protected function _unwrap()
public function _unwrap()
{
$iterator = $this;
while (get_class($iterator) === 'Cake\Collection\Collection') {
Expand Down

0 comments on commit 04675ba

Please sign in to comment.