Skip to content

Commit

Permalink
Update annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 30, 2020
1 parent be3f405 commit 37c6a5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
use loophp\collection\Contract\Operation\Reductionable;
use loophp\collection\Contract\Operation\Reverseable;
use loophp\collection\Contract\Operation\RSampleable;
use loophp\collection\Contract\Operation\Runable;
use loophp\collection\Contract\Operation\Scaleable;
use loophp\collection\Contract\Operation\Shuffleable;
use loophp\collection\Contract\Operation\Sinceable;
Expand Down Expand Up @@ -154,15 +153,14 @@
* @template-extends Splitable<TKey, T>
* @template-extends Tailable<TKey, T>
* @template-extends Transposeable<TKey, T>
* @template-extends Unpack<TKey, T>
* @template-extends Unpackable<TKey, T>
* @template-extends Unpairable<TKey, T>
* @template-extends Untilable<TKey, T>
* @template-extends Unwrapable<TKey, T>
* @template-extends Windowable<TKey, T>
* @template-extends Wrapable<TKey, T>
* @template-extends Zipable<TKey, T>
* @template-extends \IteratorAggregate<TKey, T>
* @template-extends Runable<TKey, T>
*/
interface Collection extends
Allable,
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Operation/Allable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Allable
/**
* Get all items from the collection.
*
* @return array<TKey, T>
* @psalm-return array<TKey, T>
* An array containing all the elements of the collection.
*/
public function all(): array;
Expand Down
40 changes: 30 additions & 10 deletions src/Operation/Reduce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace loophp\collection\Operation;

use Closure;
use Generator;
use Iterator;

/**
Expand All @@ -14,20 +15,39 @@
*/
final class Reduce extends AbstractOperation
{
// phpcs:disable
/**
* @psalm-param \Iterator<TKey, T> $collection
*
* @return mixed|null
* @psalm-return T|scalar|null|\Iterator<TKey, T>
* @psalm-return Closure(callable(T|null, T, TKey, Iterator<TKey, T>): T): Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
// phpcs:enable
public function __invoke(): Closure
{
return static function (callable $callback): Closure {
return static function ($initial = null) use ($callback): Closure {
return static function (Iterator $iterator) use ($callback, $initial) {
return yield from FoldLeft::of()($callback)($initial)($iterator);
};
return
/**
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>): T $callback
*
* @psalm-return Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (callable $callback): Closure {
return
/**
* @psalm-param T|null $initial
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
*
* @param mixed|null $initial
*/
static function ($initial = null) use ($callback): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator) use ($callback, $initial): Generator {
return yield from FoldLeft::of()($callback)($initial)($iterator);
};
};
};
};
}
}

0 comments on commit 37c6a5c

Please sign in to comment.