Skip to content

Commit

Permalink
refactor: Minor types fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Mar 30, 2021
1 parent cdb1a71 commit 77db2cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Contract/Operation/Partitionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Partitionable
* @param callable ...$callbacks
* @psalm-param callable(T, TKey):bool ...$callbacks
*
* @psalm-return \loophp\collection\Collection<int, array{int, array<0: TKey, 1: T>}>
* @psalm-return \loophp\collection\Collection<int, array<int, array{0: TKey, 1: T}>>
*/
public function partition(callable ...$callbacks): Collection;
}
2 changes: 0 additions & 2 deletions src/Iterator/ArrayCacheIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function __construct(Iterator $iterator)
*/
public function current()
{
/** @psalm-var array{TKey, T} $data */
$data = $this->getTupleFromCache($this->key);

return $data[1];
Expand All @@ -50,7 +49,6 @@ public function current()
*/
public function key()
{
/** @psalm-var array{TKey, T} $data */
$data = $this->getTupleFromCache($this->key);

return $data[0];
Expand Down
10 changes: 7 additions & 3 deletions src/Operation/Pipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand All @@ -18,7 +20,9 @@
final class Pipe extends AbstractOperation
{
/**
* @psalm-return Closure(callable(Iterator<TKey, T>): Iterator<TKey, T> ...): Closure (Iterator<TKey, T>): Iterator<TKey, T>
* @psalm-return Closure(...callable(Iterator<TKey, T>):Generator<TKey, T, mixed, mixed>):Closure(Iterator<TKey, T>):Iterator<TKey, T>
*
* @return Closure (Iterator<TKey, T>): Iterator<TKey, T>
*/
public function __invoke(): Closure
{
Expand All @@ -38,11 +42,11 @@ static function (Iterator $iterator) use ($operations): Iterator {
$callback =
/**
* @psalm-param Iterator<TKey, T> $iterator
* @psalm-param callable(Iterator<TKey, T>): Iterator<TKey, T> $fn
* @psalm-param callable(Iterator<TKey, T>): Iterator<TKey, T> $callable
*
* @psalm-return Iterator<TKey, T>
*/
static fn (Iterator $iterator, callable $fn): Iterator => $fn($iterator);
static fn (Iterator $iterator, callable $callable): Iterator => call_user_func($callable, $iterator);

return array_reduce($operations, $callback, $iterator);
};
Expand Down
19 changes: 9 additions & 10 deletions src/Operation/Reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ final class Reverse extends AbstractOperation
*/
public function __invoke(): Closure
{
/**
* @param array $carry
* @psalm-param array<int, array{0: TKey, 1: T}> $carry
*
* @param array $value
* @psalm-param array{0: TKey, 1: T} $value
*
* @psalm-return array<int, array{0: TKey, 1: T}>
*/
$callback = static fn (array $carry, array $value): array => [...$value, ...$carry];
$callback =
/**
* @psalm-param list<array{0: TKey, 1: T}> $carry
*
* @psalm-param list<array{0: TKey, 1: T}> $value
*
* @psalm-return list<array{0: TKey, 1: T}>
*/
static fn (array $carry, array $value): array => [...$value, ...$carry];

/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
Expand Down

0 comments on commit 77db2cd

Please sign in to comment.