Skip to content
Permalink
Browse files

Making _unwrap() a method of the ColletionInterface

  • Loading branch information...
lorenzo committed May 10, 2015
1 parent 6c4e7ab commit 04675bafce242090aad9f90412de7914ed18a08b
Showing with 13 additions and 6 deletions.
  1. +9 −0 src/Collection/CollectionInterface.php
  2. +4 −6 src/Collection/CollectionTrait.php
@@ -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();
}
@@ -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);
}
@@ -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') {

0 comments on commit 04675ba

Please sign in to comment.
You can’t perform that action at this time.