Skip to content

Commit

Permalink
refactor: Minor style and type changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 11, 2021
1 parent 6c14308 commit 34d626c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/Operation/DropWhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static function (callable ...$callbacks): Closure {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

return
/**
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Forget.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ static function (...$keys): Closure {
*
* @param mixed $key
* @psalm-param TKey $key
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => false === in_array($key, $keys, true);
static fn ($value, $key): bool => false === in_array($key, $keys, true);

/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, T> $filter */
$filter = Filter::of()($filterCallbackFactory($keys));
Expand Down
9 changes: 5 additions & 4 deletions src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static function (callable ...$callbacks): Closure {
* @psalm-return Generator<int|TKey, bool>
*/
static function (Iterator $iterator) use ($callbacks): Generator {
$callback =
/** @psalm-var list<Closure(T, TKey, Iterator<TKey, T>): bool> $callbacks */
$callbacks = array_map(
/**
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callback
*/
Expand All @@ -51,9 +52,9 @@ static function (Iterator $iterator) use ($callbacks): Generator {
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => $callback($value, $key, $iterator) === $value;

$callbacks = array_map($callback, $callbacks);
static fn ($value, $key, Iterator $iterator): bool => $callback($value, $key, $iterator) === $value,
$callbacks
);

foreach ($iterator as $key => $current) {
/** @psalm-var Iterator<int, bool> $result */
Expand Down
7 changes: 1 addition & 6 deletions src/Operation/Intersect.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ static function (...$values): Closure {
/**
* @param mixed $value
* @psalm-param T $value
*
* @param mixed $key
* @psalm-param TKey $key
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => in_array($value, $values, true);
static fn ($value): bool => in_array($value, $values, true);

/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, T> $filter */
$filter = Filter::of()($filterCallbackFactory($values));
Expand Down
36 changes: 15 additions & 21 deletions src/Operation/MatchOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,21 @@ static function (callable ...$callbacks) use ($matcher): Closure {
*
* @psalm-return Closure(T, TKey, Iterator<TKey, T>): bool
*/
static function (array $callbacks): Closure {
return
/**
* @psalm-param T $value
*
* @param mixed $value
*
* @psalm-param TKey $key
*
* @param mixed $key
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static function ($value, $key, Iterator $iterator) use ($callbacks): bool {
return array_reduce(
$callbacks,
static fn (bool $carry, callable $callback): bool => ($carry || $callback($value, $key, $iterator)),
false
);
};
};
static fn (array $callbacks): Closure =>
/**
* @param mixed $value
* @psalm-param T $value
*
* @param mixed $key
* @psalm-param TKey $key
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => array_reduce(
$callbacks,
static fn (bool $carry, callable $callback): bool => $carry || $callback($value, $key, $iterator),
false
);

$callback = $callbackReducer($callbacks);

Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Since.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

$result = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Split.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static function (Iterator $iterator) use ($type, $callbacks): Generator {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

foreach ($iterator as $key => $value) {
$callbackReturn = array_reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/TakeWhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

foreach ($iterator as $key => $current) {
$result = array_reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Until.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
* @psalm-param bool $carry
* @psalm-param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || ($callable($current, $key, $iterator));
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);

foreach ($iterator as $key => $current) {
yield $key => $current;
Expand Down

0 comments on commit 34d626c

Please sign in to comment.