Skip to content

Commit

Permalink
refactor: Minor - Fix typing information.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 3, 2021
1 parent 837bd76 commit c7aebfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
32 changes: 18 additions & 14 deletions src/Operation/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ public function __invoke(): Closure
*
* @psalm-return Closure(Iterator<TKey, T>): Generator<T, T>
*/
static fn (...$keys): Closure => static function (Iterator $iterator) use ($keys): Generator {
$keys = new ArrayIterator($keys);

while ($iterator->valid() && $keys->valid()) {
yield $keys->current() => $iterator->current();

$iterator->next();
$keys->next();
}

if ($iterator->valid() !== $keys->valid()) {
trigger_error('Both keys and values must have the same amount of items.', E_USER_WARNING);
}
};
static fn (...$keys): Closure =>
/**
* @psalm-param Iterator<TKey, T> $iterator
*/
static function (Iterator $iterator) use ($keys): Generator {
$keys = new ArrayIterator($keys);

while ($iterator->valid() && $keys->valid()) {
yield $keys->current() => $iterator->current();

$iterator->next();
$keys->next();
}

if ($iterator->valid() !== $keys->valid()) {
trigger_error('Both keys and values must have the same amount of items.', E_USER_WARNING);
}
};
}
}
6 changes: 3 additions & 3 deletions src/Operation/Distinct.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public function __invoke(): Closure
* @psalm-param T $value
*/
static function ($value) use (&$seen): bool {
/** @psalm-var list<T> $seen */
$return = !in_array($value, $seen, true);
$return = in_array($value, $seen, true);

/** @psalm-var list<T> $seen */
$seen[] = $value;

return $return;
return !$return;
};

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

0 comments on commit c7aebfe

Please sign in to comment.