Skip to content

Commit 2e88e46

Browse files
authored
Augment fold() and reduce() with type variables (#132)
1 parent d1f6deb commit 2e88e46

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Standard.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,12 @@ public function skipWhile(callable $predicate): self
478478
/**
479479
* Reduces input values to a single value. Defaults to summation. This is a terminal operation.
480480
*
481+
* @template T
482+
*
481483
* @param ?callable $func function (mixed $carry, mixed $item) { must return updated $carry }
482-
* @param ?mixed $initial initial value for a $carry
484+
* @param T $initial The initial initial value for a $carry
483485
*
484-
* @return ?mixed
486+
* @return int|T
485487
*/
486488
public function reduce(?callable $func = null, $initial = null)
487489
{
@@ -491,10 +493,12 @@ public function reduce(?callable $func = null, $initial = null)
491493
/**
492494
* Reduces input values to a single value. Defaults to summation. Requires an initial value. This is a terminal operation.
493495
*
494-
* @param mixed $initial initial value for a $carry
496+
* @template T
497+
*
498+
* @param T $initial initial value for a $carry
495499
* @param ?callable $func function (mixed $carry, mixed $item) { must return updated $carry }
496500
*
497-
* @return ?mixed
501+
* @return T
498502
*/
499503
public function fold($initial, ?callable $func = null)
500504
{

0 commit comments

Comments
 (0)