Skip to content

Commit

Permalink
Update the ::iterate() static method.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 9, 2019
1 parent 9e96a94 commit 994772c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions spec/drupol/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,16 +598,17 @@ public function it_can_intersperse(): void
public function it_can_iterate(): void
{
$this
->beConstructedThrough('iterate', [static function ($item) {
return [$item[1], $item[0] + $item[1]];
->beConstructedThrough('iterate', [static function ($value1, $value2) {
return [$value2, $value1 + $value2];
}, 0, 1]);

$this
->map(static function ($item) {
return $item[0];
})
->limit(10)
->shouldIterateAs([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]);
->all()
->shouldReturn([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]);
}

public function it_can_keys(): void
Expand Down
4 changes: 3 additions & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ static function () use ($parameters, $callback) {
}

while (true) {
$parameters = $callback($parameters);
$parameters = $callback(...$parameters);

yield $parameters;

$parameters = (array) $parameters;
}
}
);
Expand Down

0 comments on commit 994772c

Please sign in to comment.