Skip to content

Commit

Permalink
Augment fold() and reduce() with type variables (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai authored Jun 15, 2023
1 parent d1f6deb commit 2e88e46
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,12 @@ public function skipWhile(callable $predicate): self
/**
* Reduces input values to a single value. Defaults to summation. This is a terminal operation.
*
* @template T
*
* @param ?callable $func function (mixed $carry, mixed $item) { must return updated $carry }
* @param ?mixed $initial initial value for a $carry
* @param T $initial The initial initial value for a $carry
*
* @return ?mixed
* @return int|T
*/
public function reduce(?callable $func = null, $initial = null)
{
Expand All @@ -491,10 +493,12 @@ public function reduce(?callable $func = null, $initial = null)
/**
* Reduces input values to a single value. Defaults to summation. Requires an initial value. This is a terminal operation.
*
* @param mixed $initial initial value for a $carry
* @template T
*
* @param T $initial initial value for a $carry
* @param ?callable $func function (mixed $carry, mixed $item) { must return updated $carry }
*
* @return ?mixed
* @return T
*/
public function fold($initial, ?callable $func = null)
{
Expand Down

0 comments on commit 2e88e46

Please sign in to comment.