Skip to content

Commit

Permalink
Update Collapse operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 6, 2020
1 parent baa9caf commit 795aa06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,26 @@ public function it_can_chunk(): void

public function it_can_collapse(): void
{
$this::fromIterable(range('A', 'J'))
->chunk(2)
$generator = static function () {
yield 0 => 'A';

yield 1 => 'B';

yield 'foo' => 'C';

yield 0 => 'E';

yield 1 => 'F';
};

$this::fromIterable([
['A', 'B', 'foo' => 'C'],
'D',
['E', 'F'],
'G',
])
->collapse()
->shouldIterateAs(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']);
->shouldIterateAs($generator());

$this::fromIterable(range('A', 'E'))
->collapse()
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function __invoke(): Closure
continue;
}

foreach ($value as $subValue) {
yield $subValue;
foreach ($value as $subKey => $subValue) {
yield $subKey => $subValue;
}
}
};
Expand Down

0 comments on commit 795aa06

Please sign in to comment.