Skip to content

Commit

Permalink
refactor: Use call_user_func_array.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Mar 30, 2021
1 parent 1e8de4a commit 82c5841
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Operation/DropWhile.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -60,7 +62,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 || call_user_func_array($callable, [$current, $key, $iterator]);

$result = true;

Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Every.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -52,7 +54,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 || call_user_func_array($callable, [$current, $key, $iterator]);

return
/**
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Map.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -48,7 +50,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
*
* @psalm-return T
*/
static fn ($carry, callable $callback) => $callback($carry, $key, $iterator);
static fn ($carry, callable $callback) => call_user_func_array($callback, [$carry, $key, $iterator]);

foreach ($iterator as $key => $value) {
yield $key => array_reduce($callbacks, $callbackFactory($key), $value);
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Partition.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -60,7 +62,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 || call_user_func_array($callable, [$current, $key, $iterator]);

$true = $false = [];

Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Since.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -60,7 +62,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 || call_user_func_array($callable, [$current, $key, $iterator]);

$result = false;

Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Split.php
Expand Up @@ -9,6 +9,8 @@
use Iterator;
use loophp\collection\Contract\Operation\Splitable;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -67,7 +69,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 || call_user_func_array($callable, [$current, $key, $iterator]);

foreach ($iterator as $key => $value) {
$callbackReturn = array_reduce(
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/TakeWhile.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -60,7 +62,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 || call_user_func_array($callable, [$current, $key, $iterator]);

foreach ($iterator as $key => $current) {
$result = array_reduce(
Expand Down
4 changes: 3 additions & 1 deletion src/Operation/Until.php
Expand Up @@ -8,6 +8,8 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -60,7 +62,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 || call_user_func_array($callable, [$current, $key, $iterator]);

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

0 comments on commit 82c5841

Please sign in to comment.