diff --git a/src/Contract/Operation/Reductionable.php b/src/Contract/Operation/Reductionable.php index f4acf3a9d..c7d2a8779 100644 --- a/src/Contract/Operation/Reductionable.php +++ b/src/Contract/Operation/Reductionable.php @@ -9,6 +9,7 @@ namespace loophp\collection\Contract\Operation; +use Iterator; use loophp\collection\Contract\Collection; /** @@ -18,11 +19,16 @@ interface Reductionable { /** - * Reduce a collection of items through a given callback. + * Reduce a collection of items through a given callback and + * and yield each intermediary results. * - * @param mixed $initial + * @template V + * @template W * - * @return Collection + * @param callable(V|W, T, TKey, Iterator): W $callback + * @param V $initial + * + * @return Collection */ public function reduction(callable $callback, $initial = null): Collection; } diff --git a/src/Operation/Reduction.php b/src/Operation/Reduction.php index 3f04ba34f..9e314843e 100644 --- a/src/Operation/Reduction.php +++ b/src/Operation/Reduction.php @@ -27,28 +27,29 @@ final class Reduction extends AbstractOperation * @pure * * @template V + * @template W * - * @return Closure(callable(V, T, TKey, Iterator): V): Closure (V): Closure(Iterator): Generator + * @return Closure(callable(V|W, T, TKey, Iterator): W): Closure(V): Closure(Iterator): Generator */ public function __invoke(): Closure { return /** - * @param callable(V, T, TKey, Iterator): V $callback + * @param callable(V|W, T, TKey, Iterator): W $callback * - * @return Closure(V): Closure(Iterator): Generator + * @return Closure(V): Closure(Iterator): Generator */ static fn (callable $callback): Closure => /** * @param V $initial * - * @return Closure(Iterator): Generator + * @return Closure(Iterator): Generator */ static fn ($initial): Closure => /** * @param Iterator $iterator * - * @return Generator + * @return Generator */ static function (Iterator $iterator) use ($callback, $initial): Generator { foreach ($iterator as $key => $value) {