Skip to content

Commit

Permalink
Optimize Zip operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 7, 2020
1 parent 0070b45 commit f87d6fc
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Operation/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Generator;
use loophp\collection\Contract\Operation;
use loophp\collection\Iterator\IterableIterator;
use loophp\collection\Transformation\Run;
use MultipleIterator;

/**
Expand Down Expand Up @@ -39,18 +38,11 @@ public function __invoke(): Closure
$iterables = $this->iterables;

return static function (iterable $collection) use ($iterables): Generator {
$items = (
new Run(
(new Walk(
static function (iterable $iterable): IterableIterator {
return new IterableIterator($iterable);
}
))
))(array_merge([$collection], $iterables));
$mit = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mit->attachIterator(new IterableIterator($collection));

foreach (new IterableIterator($items) as $iterator) {
$mit->attachIterator($iterator);
foreach ($iterables as $iterator) {
$mit->attachIterator(new IterableIterator($iterator));
}

foreach ($mit as $values) {
Expand Down

0 comments on commit f87d6fc

Please sign in to comment.