Skip to content

Commit

Permalink
refactor: Simplify logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 16, 2022
1 parent 4396013 commit 7a20ecb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/SimpleCachingIteratorAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
final class SimpleCachingIteratorAggregate implements IteratorAggregate
{
private bool $hasStarted = false;

/**
* @var CachingIterator<array-key, T>
*/
Expand All @@ -47,15 +45,11 @@ public function __construct(Iterator $iterator)
*/
public function getIterator(): Generator
{
if ($this->hasStarted) {
do {
$this->iterator->next();
} while ($this->iterator->valid());
yield from $this->iterator->getCache();

yield from $this->iterator->getCache();
}
while ($this->iterator->hasNext()) {
$this->iterator->next();

for ($this->hasStarted = true,$this->iterator->next(); $this->iterator->valid(); $this->iterator->next()) {
yield $this->iterator->key() => $this->iterator->current();
}
}
Expand Down

0 comments on commit 7a20ecb

Please sign in to comment.