Creates a Closure that emits each intermediate accumulation of a right-fold over an array or iterable, ending with the initial value.
/**
* @param callable(mixed $carry, mixed $value):mixed $function
* @param mixed $initialValue
* @return Closure(iterable<int|string, mixed>):(array<int, mixed>|\Generator<int, mixed>)
*/
Arrays\scanR(callable $function, $initialValue): ClosureWhen Arrays\scanR() is called, it returns the following Closure which can be used like a regular function.
/**
* @param iterable<int|string, mixed> $source
* @return array<int, mixed>|\Generator<int, mixed>
*/
$function (iterable $source): array|\GeneratorThis can be used to create a simple closure which can be used as a regular function.
$fromRight = Arrays\scanR(fn($acc, $v) => $acc . $v, '');
print_r($fromRight(['a', 'b', 'c']));
// ['cba', 'cb', 'c', '']