Skip to content

Commit

Permalink
Update the Chunk operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 1, 2019
1 parent 3306602 commit d61bac3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spec/drupol/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function it_can_chunk(): void
$this::with(\range('A', 'F'))
->chunk(2)
->all()
->shouldReturn([[0 => 'A', 1 => 'B'], [2 => 'C', 3 => 'D'], [4 => 'E', 5 => 'F']]);
->shouldReturn([[0 => 'A', 1 => 'B'], [0 => 'C', 1 => 'D'], [0 => 'E', 1 => 'F']]);

$this::with(\range('A', 'F'))
->chunk(0)
Expand All @@ -239,7 +239,7 @@ public function it_can_chunk(): void
$this::with(\range('A', 'F'))
->chunk(1)
->all()
->shouldReturn([[0 => 'A'], [1 => 'B'], [2 => 'C'], [3 => 'D'], [4 => 'E'], [5 => 'F']]);
->shouldReturn([[0 => 'A'], [0 => 'B'], [0 => 'C'], [0 => 'D'], [0 => 'E'], [0 => 'F']]);
}

public function it_can_collapse(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function on(iterable $collection): \Closure
$iterator = new ClosureIterator(
static function () use ($collection) {
foreach ($collection as $key => $value) {
yield $key => $value;
yield $value;
}
}
);
Expand All @@ -53,7 +53,7 @@ static function () use ($collection) {
$values = [];

for ($i = 0; $iterator->valid() && $i < $length; $i++, $iterator->next()) {
$values[$iterator->key()] = $iterator->current();
$values[] = $iterator->current();
}

yield new \ArrayIterator($values);
Expand Down

0 comments on commit d61bac3

Please sign in to comment.