Skip to content

Commit

Permalink
Update and fix Psalm phpdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 4, 2020
1 parent a94f3ee commit 91c8900
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Operation/Flatten.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ static function (Iterator $iterator, int $depth): Generator {
if (false === is_iterable($value)) {
yield $value;
} elseif (1 === $depth) {
/** @psalm-var T $subValue */
foreach ($value as $subValue) {
yield $subValue;
}
} elseif (is_array($value)) {
/** @psalm-var T $subValue */
foreach ((new Run(new Flatten($depth - 1)))(new ArrayIterator($value)) as $subValue) {
yield $subValue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Intersperse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function __construct($element, int $atEvery = 1, int $startAt = 0)

public function __invoke(): Closure
{
/** @var int $every */
$every = $this->get('atEvery');
/** @var int $startAt */
$startAt = $this->get('startAt');

if (0 > $every) {
Expand All @@ -55,7 +57,7 @@ public function __invoke(): Closure
* @param mixed $element
* @psalm-param T $element
*
* @psalm-return \Generator<int, T>
* @psalm-return \Generator<int|TKey, T>
*/
static function (Iterator $iterator, $element, int $every, int $startAt): Generator {
foreach ($iterator as $key => $value) {
Expand Down
1 change: 1 addition & 0 deletions src/Operation/Pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __invoke(): Closure
* @psalm-return \Generator<TKey, T>
*/
static function (Iterator $iterator): Generator {
/** @psalm-var list<int, list<T|TKey>> $chunk */
foreach ((new Run(new Chunk(2)))($iterator) as $chunk) {
/** @psalm-var array{TKey, T} $chunk */
$chunk = array_values($chunk);
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Reduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function __invoke(): Closure
return
/**
* @psalm-param \Iterator<TKey, T> $iterator
* @psalm-param callable(T|null, T, TKey):(T|null) $callable
* @psalm-param callable(T|null, T, TKey):(T|null) $callback
*
* @param mixed $initial
* @psalm-param T|null $initial
*
* @psalm-return \Generator<int, T|null>
* @psalm-return \Generator<TKey, T|null>
*/
static function (Iterator $iterator, callable $callback, $initial): Generator {
foreach ($iterator as $key => $value) {
yield $initial = $callback($initial, $value, $key);
yield $key => ($initial = $callback($initial, $value, $key));
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Unpair.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(): Closure
/**
* @psalm-param \Iterator<TKey, T> $iterator
*
* @psalm-return \Generator<TKey, T>
* @psalm-return \Generator<int, array{TKey, T}>
*/
static function (Iterator $iterator): Generator {
foreach ($iterator as $key => $value) {
Expand Down

0 comments on commit 91c8900

Please sign in to comment.