Skip to content

Commit

Permalink
Using map() instead of unfold() in Collection::chunk() as it is faster
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 28, 2015
1 parent 68b30d0 commit 18bc7b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Collection/CollectionTrait.php
Expand Up @@ -607,7 +607,7 @@ public function zipWith($items, $callable)
*/
public function chunk($chunkSize)
{
return $this->unfold(function ($v, $k, $iterator) use ($chunkSize) {
return $this->map(function ($v, $k, $iterator) use ($chunkSize) {
$values = [$v];
for ($i = 1; $i < $chunkSize; $i++) {
$iterator->next();
Expand All @@ -617,7 +617,7 @@ public function chunk($chunkSize)
$values[] = $iterator->current();
}

return empty($values) ? $values : [$values];
return $values;
});
}

Expand Down

0 comments on commit 18bc7b5

Please sign in to comment.