Skip to content

Commit

Permalink
Update annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 31, 2020
1 parent 8f668d7 commit 5cf2513
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
* @template-extends Windowable<TKey, T>
* @template-extends Wrapable<TKey, T>
* @template-extends Zipable<TKey, T>
* @template-extends \IteratorAggregate<TKey, T>
* @template-extends IteratorAggregate<TKey, T>
*/
interface Collection extends
Allable,
Expand Down
2 changes: 1 addition & 1 deletion src/Iterator/CacheIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @psalm-template TKey of array-key
* @psalm-template T
*
* @implements \Iterator<TKey, T>
* @implements Iterator<TKey, T>
*/
final class CacheIterator implements Iterator, OuterIterator
{
Expand Down
10 changes: 5 additions & 5 deletions src/Iterator/ClosureIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @psalm-template T
*
* @extends ProxyIterator<TKey, T>
* @implements \Iterator<TKey, T>
* @implements Iterator<TKey, T>
*/
final class ClosureIterator extends ProxyIterator implements Iterator, OuterIterator
{
Expand All @@ -27,20 +27,20 @@ final class ClosureIterator extends ProxyIterator implements Iterator, OuterIter

/**
* @var callable
* @psalm-var callable(T...):(\Generator<TKey, T>)
* @psalm-var callable(T...):(Generator<TKey, T>)
*/
private $callable;

/**
* @var Closure
* @psalm-var Closure(callable(T...):\Generator<TKey, T>, list<T>):(\Generator<TKey, T>)
* @psalm-var Closure(callable(T...):Generator<TKey, T>, list<T>):(Generator<TKey, T>)
*/
private $generator;

/**
* @param mixed ...$arguments
* @psalm-param T ...$arguments
* @psalm-param callable(T...):(\Generator<TKey,T>) $callable
* @psalm-param callable(T...):(Generator<TKey,T>) $callable
*/
public function __construct(callable $callable, ...$arguments)
{
Expand All @@ -61,7 +61,7 @@ public function rewind(): void
/**
* Init the generator if not initialized yet.
*
* @psalm-return \Generator<TKey, T>
* @psalm-return Generator<TKey, T>
*/
private function getGenerator(): Generator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Iterator/IterableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @psalm-template T
*
* @extends ProxyIterator<TKey, T>
* @implements \Iterator<TKey, T>
* @implements Iterator<TKey, T>
*/
final class IterableIterator extends ProxyIterator implements Iterator, OuterIterator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Iterator/ProxyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function current()
}

/**
* @psalm-return \Iterator<TKey, T>
* @psalm-return Iterator<TKey, T>
*/
public function getInnerIterator(): Iterator
{
Expand Down
4 changes: 2 additions & 2 deletions src/Iterator/ResourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @psalm-template T
*
* @extends ProxyIterator<TKey, T>
* @implements \Iterator<TKey, T>
* @implements Iterator<TKey, T>
*/
final class ResourceIterator extends ProxyIterator implements Iterator, OuterIterator
{
Expand All @@ -27,7 +27,7 @@ public function __construct($resource)
/**
* @param resource $resource
*
* @psalm-return \Generator<int, T>
* @psalm-return Generator<int, T>
*/
static function ($resource): Generator {
while (false !== $chunk = fgetc($resource)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Combinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static function (Iterator $iterator) use ($length, $getCombinations): Generator
$dataset = iterator_to_array($iterator);

if (0 < $length) {
return yield from $getCombinations($dataset, $length);
return yield from $getCombinations($dataset, (int) $length);
}

$collectionSize = count($dataset);
Expand Down
4 changes: 4 additions & 0 deletions src/Operation/Reduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public function __invoke(): Closure
return
/**
* @psalm-param callable(T|null, T, TKey):(T|null) $callback
*
* @psalm-return Closure(T|null): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (callable $callback): Closure {
return
/**
* @param mixed|null $initial
* @psalm-param T|null $initial
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function ($initial = null) use ($callback): Closure {
return
Expand Down
46 changes: 25 additions & 21 deletions src/Operation/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,39 @@
final class Slice extends AbstractOperation
{
/**
* @psalm-return Closure(int): Closure(int|null): Generator<TKey, T>
* @psalm-return Closure(int): Closure(int=): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
public function __invoke(): Closure
{
return static function (int $offset): Closure {
return
/**
* @psalm-param int|null $length
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (int $length = -1) use ($offset): Closure {
return
return
/**
* @psalm-return Closure(int=): Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (int $offset): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
* @psalm-param int $length
*
* @psalm-return Generator<TKey, T>
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
static function (Iterator $iterator) use ($offset, $length): Generator {
/** @psalm-var callable(Iterator<TKey, T>): Generator<TKey, T> $skip */
$skip = Skip::of()($offset);
static function (int $length = -1) use ($offset): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator) use ($offset, $length): Generator {
/** @psalm-var callable(Iterator<TKey, T>): Generator<TKey, T> $skip */
$skip = Skip::of()($offset);

if (-1 === $length) {
return yield from $skip($iterator);
}
if (-1 === $length) {
return yield from $skip($iterator);
}

return yield from Compose::of()($skip, Limit::of()($length)(0))($iterator);
return yield from Compose::of()($skip, Limit::of()($length)(0))($iterator);
};
};
};
};
};
}
}

0 comments on commit 5cf2513

Please sign in to comment.