Skip to content

Commit

Permalink
refactor: Use EmptyIterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 20, 2020
1 parent f1eeb5d commit 4390145
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayIterator;
use Closure;
use EmptyIterator;
use Generator;
use Iterator;

Expand Down Expand Up @@ -42,7 +43,7 @@ static function (Iterator $iterator) use ($sizes): Generator {

foreach ($iterator as $value) {
if (0 >= $sizesIterator->current()) {
return yield from [];
return new EmptyIterator();
}

if (count($values) !== $sizesIterator->current()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace loophp\collection\Operation;

use Closure;
use EmptyIterator;
use Generator;
use Iterator;
use LimitIterator;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function __invoke(): Closure
*/
static function (Iterator $iterator) use ($offsets): Generator {
if (!$iterator->valid()) {
return yield from [];
return new EmptyIterator();
}

return yield from new LimitIterator($iterator, array_sum($offsets));
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace loophp\collection\Operation;

use Closure;
use EmptyIterator;
use Generator;
use Iterator;

Expand All @@ -28,7 +29,7 @@ public function __invoke(): Closure
*/
static function (Iterator $iterator): Generator {
if (!$iterator->valid()) {
return yield from [];
return new EmptyIterator();
}

return yield $iterator->key() => $iterator->current();
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CachingIterator;
use Closure;
use EmptyIterator;
use Generator;
use Iterator;

Expand All @@ -29,7 +30,7 @@ public function __invoke(): Closure
*/
static function (Iterator $iterator): Generator {
if (!$iterator->valid()) {
return yield from [];
return new EmptyIterator();
}

$cachingIterator = new CachingIterator($iterator, CachingIterator::FULL_CACHE);
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Times.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace loophp\collection\Operation;

use Closure;
use EmptyIterator;
use Generator;
use Iterator;

Expand Down Expand Up @@ -39,7 +40,7 @@ public function __invoke(): Closure
*/
static function (?Iterator $iterator = null) use ($number, $callback): Generator {
if (1 > $number) {
yield from [];
return new EmptyIterator();
}

$callback ??= static fn (int $value): int => $value;
Expand Down

0 comments on commit 4390145

Please sign in to comment.