Skip to content

Commit

Permalink
refactor: Simplify fromGenerator operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 29, 2021
1 parent b2028d8 commit b2e1dc9
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
use loophp\iterators\CachingIteratorAggregate;
use loophp\iterators\ClosureIterator;
use loophp\iterators\IterableIterator;
use NoRewindIterator;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

Expand Down Expand Up @@ -485,15 +486,7 @@ public static function fromGenerator(Generator $generator): self
{
return self::fromIterable(
new CachingIteratorAggregate(
new ClosureIterator(
static function (Generator $generator): Generator {
while ($generator->valid()) {
yield $generator->key() => $generator->current();
$generator->next();
}
},
[$generator]
)
new NoRewindIterator($generator)
)
);
}
Expand Down

0 comments on commit b2e1dc9

Please sign in to comment.