Skip to content

Commit

Permalink
Use ReductionIterableAggregate.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 24, 2022
1 parent 3b49c3a commit a168b6d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Operation/Reduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Closure;
use Generator;
use loophp\iterators\ReductionIterableAggregate;

/**
* @immutable
Expand Down Expand Up @@ -48,13 +49,6 @@ public function __invoke(): Closure
*
* @return Generator<TKey, W>
*/
static function (iterable $iterable) use ($callback, $initial): Generator {
foreach ($iterable as $key => $value) {
/** @var W $initial */
$initial = $callback($initial, $value, $key, $iterable);

yield $key => $initial;
}
};
static fn (iterable $iterable): Generator => yield from new ReductionIterableAggregate($iterable, Closure::fromCallable($callback), $initial);
}
}

0 comments on commit a168b6d

Please sign in to comment.