From b2e1dc97fb71a99cefd49e9307c324c48c89ee65 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 29 Dec 2021 19:06:51 +0100 Subject: [PATCH] refactor: Simplify `fromGenerator` operation. --- src/Collection.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index 3c68f769d..84a92f0dc 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -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; @@ -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) ) ); }