for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace loophp\fpt;
use Closure;
// phpcs:disable Generic.Files.LineLength.TooLong
/**
* @psalm-immutable
*/
final class Reduction
{
* @psalm-pure
public static function of(): Closure
return static fn (callable ...$callables): Closure => static fn ($init = null): Closure => static function (iterable ...$iterables) use ($callables, $init) {
foreach ($iterables as $iterable) {
foreach ($iterable as $key => $item) {
yield $key => ($init = array_reduce(
$callables,
static fn ($init, callable $callback) => $callback($init, $item, $key, $iterable),
$init
));
}
};