Skip to content

Commit

Permalink
Revert "refactor: Use call_user_func_array() functions."
Browse files Browse the repository at this point in the history
This reverts commit 614a663.
  • Loading branch information
drupol committed Apr 4, 2021
1 parent 78b5e2e commit 54327af
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 48 deletions.
3 changes: 1 addition & 2 deletions src/Operation/AsyncMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use function Amp\ParallelFunctions\parallel;
use function Amp\Promise\wait;
use function Amp\Sync\ConcurrentIterator\map;
use function call_user_func_array;
use function function_exists;

// phpcs:disable
Expand Down Expand Up @@ -66,7 +65,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
*
* @psalm-return T
*/
static fn ($carry, callable $callback) => call_user_func_array($callback, [$carry, $key]);
static fn ($carry, callable $callback) => $callback($carry, $key);

$callback =
/**
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/DropWhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

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

$result = true;

Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -54,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 || call_user_func_array($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/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -64,7 +62,7 @@ static function (?callable $callable = null): Closure {
* @psalm-return non-empty-array<TKey, T|list<T>>
*/
static function (array $collect, $value, $key) use ($callback): array {
if (null !== $groupKey = call_user_func_array($callback, [$value, $key])) {
if (null !== $groupKey = $callback($value, $key)) {
$collect[$groupKey][] = $value;
} else {
$collect[$key] = $value;
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -54,7 +52,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => call_user_func_array($callback, [$value, $key, $iterator]) === $value,
static fn ($value, $key, Iterator $iterator): bool => $callback($value, $key, $iterator) === $value,
$callbacks
);

Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

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

foreach ($iterator as $key => $value) {
yield $key => array_reduce($callbacks, $callbackFactory($key), $value);
Expand Down
6 changes: 2 additions & 4 deletions src/Operation/MatchOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -56,7 +54,7 @@ static function (callable ...$callbacks) use ($matcher): Closure {
*/
static fn ($value, $key, Iterator $iterator): bool => array_reduce(
$callbacks,
static fn (bool $carry, callable $callback): bool => $carry || call_user_func_array($callback, [$value, $key, $iterator]),
static fn (bool $carry, callable $callback): bool => $carry || $callback($value, $key, $iterator),
false
);

Expand All @@ -72,7 +70,7 @@ static function (callable ...$callbacks) use ($matcher): Closure {
*
* @psalm-param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => call_user_func_array($matcher, [$value, $key, $iterator]) === call_user_func_array($callback, [$value, $key, $iterator]);
static fn ($value, $key, Iterator $iterator): bool => $matcher($value, $key, $iterator) === $callback($value, $key, $iterator);

$dropWhileCallback =
/**
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Partition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

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

$true = $false = [];

Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Reduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -45,7 +43,7 @@ public function __invoke(): Closure
*/
static function (Iterator $iterator) use ($callback, $initial): Generator {
foreach ($iterator as $key => $value) {
yield $key => ($initial = call_user_func_array($callback, [$initial, $value, $key, $iterator]));
yield $key => ($initial = $callback($initial, $value, $key, $iterator));
}
};
}
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Since.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

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

$result = false;

Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Iterator;
use loophp\collection\Contract\Operation;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -78,7 +76,7 @@ static function (Iterator $iterator) use ($type, $callback): Iterator {
* @psalm-param array{0:TKey|T, 1:T|TKey} $left
* @psalm-param array{0:TKey|T, 1:T|TKey} $right
*/
static fn (array $left, array $right): int => call_user_func_array($callback, [$left[1], $right[1]]);
static fn (array $left, array $right): int => $callback($left[1], $right[1]);

/** @psalm-var callable(Iterator<TKey, T>): Generator<int, array{0:TKey, 1:T}> | callable(Iterator<TKey, T>): Generator<int, array{0:T, 1:TKey}> $before */
$before = Pipe::of()(...$operations['before']);
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Split.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
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 @@ -69,7 +67,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 || call_user_func_array($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
4 changes: 1 addition & 3 deletions src/Operation/TakeWhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -62,7 +60,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 || call_user_func_array($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
4 changes: 1 addition & 3 deletions src/Operation/Times.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Generator;
use Iterator;

use function call_user_func;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -47,7 +45,7 @@ static function (?Iterator $iterator = null) use ($number, $callback): Generator
$callback ??= static fn (int $value): int => $value;

for ($current = 1; $current <= $number; ++$current) {
yield call_user_func($callback, $current);
yield $callback($current);
}
};
}
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Unfold.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Closure;
use Generator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -43,7 +41,7 @@ public function __invoke(): Closure
static function () use ($parameters, $callback): Generator {
while (true) {
/** @psalm-var T $parameters */
$parameters = call_user_func_array($callback, array_values((array) $parameters));
$parameters = $callback(...array_values((array) $parameters));

yield $parameters;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/Until.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Generator;
use Iterator;

use function call_user_func_array;

/**
* @psalm-template TKey
* @psalm-template TKey of array-key
Expand Down Expand Up @@ -62,7 +60,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 || call_user_func_array($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 54327af

Please sign in to comment.