Allows you to create a function which can be used to append 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 $append
* @return Closure(string):string
*/
Strings\append(string $append): ClosureWhen Strings\append() is called, it returns the following Closure which can be used like a regular function.
/**
* @param string $toAppendOnto The string to have the sub string added to
* @return string The sliced string
* @psalm-pure
*/
$function(string $toAppendOnto): stringThis can be used to create a simple closure which can be used as a regular function.
$appendFoo = Strings\append('foo');
// Called as a function.
echo $appendFoo('Hello'); // Hellofoo
// Used in a higher order function.
$array = array_map( $appendFoo, ['Hello', 'World']);
print_r($array); // [Hellofoo, Worldfoo]This can be called inline using currying.
Strings\append('foo')('Bar'); // BarfooIf 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\append('foo'), ['Hello', 'World'])
print_r($array); // [Hellofoo, Worldfoo]