Skip to content

Commit

Permalink
fix: foldRight operation
Browse files Browse the repository at this point in the history
Fix returned types and SA annotations.
  • Loading branch information
drupol committed Jan 7, 2023
1 parent b55fec7 commit f717078
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/Contract/Operation/FoldRightable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ interface FoldRightable
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#foldright
*
* @template V
* @template W
*
* @param callable((V|W), T, TKey, iterable<TKey, T>): W $callback
* @param callable(V, T, TKey, iterable<TKey, T>): V $callback
* @param V $initial
*
* @return V|W
* @return V
*/
public function foldRight(callable $callback, mixed $initial): mixed;
}
11 changes: 5 additions & 6 deletions src/Operation/FoldRight.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,25 @@ final class FoldRight extends AbstractOperation
{
/**
* @template V
* @template W
*
* @return Closure(callable((V|W), T, TKey, iterable<TKey, T>): W): Closure(V): Closure(iterable<TKey, T>): Generator<TKey, V|W>
* @return Closure(callable(V, T, TKey, iterable<TKey, T>): V): Closure(V): Closure(iterable<TKey, T>): Generator<int, V>
*/
public function __invoke(): Closure
{
return
/**
* @param callable((V|W), T, TKey, iterable<TKey, T>): W $callback
* @param callable(V, T, TKey, iterable<TKey, T>): V $callback
*
* @return Closure(V): Closure(iterable<TKey, T>): Generator<TKey, V|W>
* @return Closure(V): Closure(iterable<TKey, T>): Generator<int, V>
*/
static fn (callable $callback): Closure =>
/**
* @param V $initial
*
* @return Closure(iterable<TKey, T>): Generator<TKey, V|W>
* @return Closure(iterable<TKey, T>): Generator<int, V>
*/
static function (mixed $initial = null) use ($callback): Closure {
/** @var Closure(iterable<TKey, T>): Generator<TKey, V|W> $pipe */
/** @var Closure(iterable<TKey, T>): Generator<int, V> $pipe */
$pipe = (new Pipe())()(
(new ScanRight())()($callback)($initial),
(new Head())()
Expand Down

0 comments on commit f717078

Please sign in to comment.