Skip to content

Commit

Permalink
refactor: Use more iterator aggregates.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 25, 2022
1 parent 0fba6da commit 7af1d80
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"require": {
"php": ">= 7.4",
"loophp/iterators": "^1.5.8"
"loophp/iterators": "^1.5.9"
},
"require-dev": {
"amphp/parallel-functions": "^1",
Expand Down
1 change: 0 additions & 1 deletion src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function __invoke(): Closure
static function (Iterator $iterator) use ($sizes): Generator {
/** @var Iterator<int, int> $sizesIterator */
$sizesIterator = Cycle::of()(new ArrayIterator($sizes));
$sizesIterator->rewind();

$values = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace loophp\collection\Operation;

use Closure;
use InfiniteIterator;
use Iterator;
use loophp\iterators\InfiniteIteratorAggregate;

/**
* @immutable
Expand All @@ -34,6 +34,6 @@ public function __invoke(): Closure
*
* @return Iterator<TKey, T>
*/
static fn (Iterator $iterator): Iterator => new InfiniteIterator($iterator);
static fn (Iterator $iterator): Iterator => yield from new InfiniteIteratorAggregate($iterator);
}
}
11 changes: 4 additions & 7 deletions src/Operation/Normalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Closure;
use Generator;
use Iterator;
use loophp\iterators\NormalizeIteratorAggregate;

/**
* @immutable
Expand All @@ -24,20 +25,16 @@ final class Normalize extends AbstractOperation
/**
* @pure
*
* @return Closure(Iterator<TKey, T>): Generator<int, T, mixed, void>
* @return Closure(Iterator<TKey, T>): Generator<int, T>
*/
public function __invoke(): Closure
{
return
/**
* @param Iterator<TKey, T> $iterator
*
* @return Generator<int, T, mixed, void>
* @return Generator<int, T>
*/
static function (Iterator $iterator): Generator {
foreach ($iterator as $value) {
yield $value;
}
};
static fn (Iterator $iterator): Generator => yield from new NormalizeIteratorAggregate($iterator);
}
}

0 comments on commit 7af1d80

Please sign in to comment.