map but with extra arguments threaded into every call — useful for mappers that need context beyond the value itself.
Creates a Closure for mapping an array or iterable where the callback receives each element alongside additional bound arguments.
/**
* @param callable(mixed ...):mixed $func
* @param mixed ...$data Extra args passed after each value.
* @return Closure(iterable<int|string, mixed>):(array<int|string, mixed>|\Generator<int|string, mixed>)
*/
Arrays\mapWith(callable $func, ...$data): ClosureWhen Arrays\mapWith() is called, it returns the following Closure which can be used like a regular function.
/**
* @param iterable<int|string, mixed> $source
* @return array<int|string, mixed>|\Generator<int|string, mixed>
*/
$function (iterable $source): array|\GeneratorThis can be used to create a simple closure which can be used as a regular function.
$join = Arrays\mapWith(fn($v, $sep, $suf) => $v . $sep . $suf, '-', '!');
print_r($join(['foo', 'bar'])); // ['foo-!', 'bar-!']This can be called inline using currying.
print_r(Arrays\mapWith('str_repeat', 2)(['ab', 'cd'])); // ['abab', 'cdcd']