Allows you to create a function which can be used to prepend a sub string to a passed string. This can either be used as part of a Higher Order Function such as array_map() or as part of a compiled/pipe function.
/**
* @param string $prepend
* @return Closure(string):string
*/
Strings\prepend(string $prepend): ClosureWhen Strings\prepend() is called, it returns the following Closure which can be used like a regular function.
/**
* @param string $toPrependOnto The string to have the sub string added to
* @return string The sliced string
* @psalm-pure
*/
$function(string $toPrependOnto): stringThis can be used to create a simple closure which can be used as a regular function.
// Creates the Closure.
$prependFoo = Strings\prepend('foo');
// Called as a function.
echo $prependFoo('Hello'); // fooHello
// Used in a higher order function.
$array = array_map( $prependFoo, ['Hello', 'World']);
print_r($array); // [fooHello, fooWorld] This can be called inline using currying.
echo Strings\prepend('foo')('Bar'); // fooBarIf you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.
$array = array_map( Strings\prepend('--'), ['foo', 'bar'] );
print_r($array); // ['--foo', '--bar']