Skip to content

Commit

Permalink
Update annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 7, 2020
1 parent 1b9ca3c commit 1bb45f2
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Contract/Operation/Cycleable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
interface Cycleable
{
/**
* @psalm-return static<TKey, T>
* @psalm-return \loophp\collection\Contract\Collection<TKey, T>
*/
public function cycle(): Collection;
}
2 changes: 1 addition & 1 deletion src/Contract/Operation/Initable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
interface Initable
{
/**
* @psalm-return static<TKey, T>
* @psalm-return \loophp\collection\Contract\Collection<TKey, T>
*/
public function init(): Collection;
}
5 changes: 2 additions & 3 deletions src/Contract/Operation/Unfoldable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ interface Unfoldable
* @psalm-template TKey of array-key
* @psalm-template T
*
* @param mixed $init
* @psalm-param T $init
* @psalm-param callable(T): T $callback
*
* @psalm-return static<T, T>
*
* @param mixed $init
* @psalm-return \loophp\collection\Contract\Collection<T, T>
*/
public static function unfold($init, callable $callback): Collection;
}
3 changes: 1 addition & 2 deletions src/Iterator/ProxyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
abstract class ProxyIterator
{
/**
* @var Generator<TKey, T>|Iterator<TKey, T>
* @psalm-var Generator<TKey, T>|Iterator<TKey, T>
*/
protected $iterator;

Expand All @@ -37,7 +37,6 @@ public function getInnerIterator(): Iterator
}

/**
* @return mixed
* @psalm-return TKey
*/
public function key()
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class Column extends AbstractOperation
{
/**
* @psalm-return Closure(Iterator<TKey, T>, array-key):(Generator<int, iterable<TKey, T>>)
* @psalm-return Closure(array-key): Closure(Iterator<TKey, T>): Generator<int, iterable<TKey, T>>
*/
public function __invoke(): Closure
{
Expand All @@ -25,6 +25,8 @@ public function __invoke(): Closure
* @param int|string $column
*
* @psalm-param array-key $column
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<int, iterable<TKey, T>>
*/
static function ($column): Closure {
return
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FoldLeft.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __invoke(): Closure
{
return
/**
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>): T
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>): T $callback
*/
static function (callable $callback): Closure {
return
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FoldRight.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __invoke(): Closure
{
return
/**
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>): T
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>): T $callback
*/
static function (callable $callback): Closure {
return
Expand Down
7 changes: 5 additions & 2 deletions src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
final class Has extends AbstractOperation
{
/**
* @psalm-return Closure(callable(TKey, T):(bool)): Closure(Iterator<TKey, T>): bool
* @psalm-return Closure(callable(TKey, T): T): Closure(Iterator<TKey, T>): Generator<int, bool>
*/
public function __invoke(): Closure
{
return
/**
* @psalm-param callable(TKey, T):(bool) $callback
* @psalm-param callable(TKey, T): T $callback
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<int, bool>
*/
static function (callable $callback): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<int, bool>
*/
static function (Iterator $iterator) use ($callback): Generator {
Expand Down
12 changes: 9 additions & 3 deletions src/Operation/IfThenElse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@
* @psalm-template TKey
* @psalm-template TKey of array-key
* @psalm-template T
*
* phpcs:disable Generic.Files.LineLength.TooLong
*/
final class IfThenElse extends AbstractOperation
{
// phpcs:disable
/**
* @psalm-return Closure(callable(T, TKey): bool): Closure(callable(T, TKey): (T)): Closure(callable(T, TKey): (T)): Generator<TKey, T>
* @psalm-return Closure(callable(T, TKey): bool): Closure(callable(T, TKey): (T)): Closure(callable(T, TKey): (T)): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
// phpcs:enable
public function __invoke(): Closure
{
return
/**
* @psalm-param callable(T, TKey): bool $condition
*
* @psalm-return Closure(callable(T, TKey): (T)): Closure(callable(T, TKey): (T)): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (callable $condition): Closure {
return
/**
* @psalm-param callable(T, TKey): (T) $then
*
* @psalm-return Closure(callable(T, TKey): (T)): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (callable $then) use ($condition): Closure {
return
/**
* @psalm-param callable(T, TKey): (T) $else
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (callable $else) use ($condition, $then): Closure {
return
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Reduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ final class Reduction extends AbstractOperation
{
// phpcs:disable
/**
* @psalm-return Closure(callable(T|null, T, TKey):(T|null)): Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
* @psalm-return Closure(callable(T|null, T, TKey, Iterator<TKey, T>):(T|null)): Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
// phpcs:enable
public function __invoke(): Closure
{
return
/**
* @psalm-param callable(T|null, T, TKey):(T|null) $callback
* @psalm-param callable(T|null, T, TKey, Iterator<TKey, T>):(T|null) $callback
*
* @psalm-return Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Operation/Unwrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
final class Unwrap extends AbstractOperation
{
/**
* @psalm-return Closure(Iterator<array-key, array<TKey, T>>): Generator<TKey, T>
*/
public function __invoke(): Closure
{
return
Expand Down
3 changes: 3 additions & 0 deletions src/Operation/Wrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
final class Wrap extends AbstractOperation
{
/**
* @psalm-return Closure(Iterator<TKey, T>): Generator<int, array<TKey, T>>
*/
public function __invoke(): Closure
{
return
Expand Down
46 changes: 27 additions & 19 deletions src/Operation/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,36 @@
*/
final class Zip extends AbstractOperation
{
/**
* @psalm-return Closure(iterable<TKey, T>...): Closure(Iterator<TKey, T>): Generator<int, list<T>>
*/
public function __invoke(): Closure
{
return static function (iterable ...$iterables): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
* @psalm-param list<iterable<TKey, T>> $iterables
*
* @psalm-return Generator<int, list<T>>
*/
static function (Iterator $iterator) use ($iterables): Generator {
$mit = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mit->attachIterator($iterator);
return
/**
* @psalm-param iterable<TKey, T> ...$iterables
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<int, list<T>>
*/
static function (iterable ...$iterables): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<int, list<T>>
*/
static function (Iterator $iterator) use ($iterables): Generator {
$mit = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mit->attachIterator($iterator);

foreach ($iterables as $iterableIterator) {
$mit->attachIterator(new IterableIterator($iterableIterator));
}
foreach ($iterables as $iterableIterator) {
$mit->attachIterator(new IterableIterator($iterableIterator));
}

foreach ($mit as $values) {
yield $values;
}
};
};
foreach ($mit as $values) {
yield $values;
}
};
};
}
}

0 comments on commit 1bb45f2

Please sign in to comment.