Strings\append()

transformer returns Closure pure
string → (string → string)
At a glance — Bind a suffix; the returned Closure tacks it onto the end of any string.

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): Closure

Returned Closure

When 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): string

Examples

Partial Application

This 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]

Curried

This can be called inline using currying.

Strings\append('foo')('Bar'); // Barfoo

Inlined with Higher Order Function

If 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]

Details

Strings Functions

Releated String manipulation Functions