Skip to content

Commit

Permalink
fix: ReductionIterableAggreate must yield the initial value first
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 28, 2022
1 parent 7cd68e6 commit 6c43b9a
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/ReductionIterableAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ public function __construct(private iterable $iterable, Closure $closure, privat
*/
public function getIterator(): Generator
{
$isEmpty = true;
$initial = $this->initial;
yield $initial = $this->initial;

foreach ($this->iterable as $key => $value) {
$isEmpty = false;
$initial = ($this->closure)($initial, $value, $key, $this->iterable);

yield $key => $initial;
}

if (true === $isEmpty) {
yield $initial;
}
}
}

0 comments on commit 6c43b9a

Please sign in to comment.