Arrays\append()

transformer lazy accepts iterable returns Closure pure
T → (Iterable → Iterable)
At a glance — Bind a value to push onto the end; the returned Closure yields the source first, then the bound value. Generator in → Generator out.

Creates a function which adds the defined values to the end of an array.

/**
 * Returns a Closure for appending a value to an array.
 *
 * @param mixed $value
 * @return Closure(array<int|string, mixed>):array<int|string, mixed>
 */
Arrays\append(mixed $value): Closure

Returned Closure

When Arrays\append() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param array<int|string, mixed> $array
  * @return array<int|string, mixed>
  */
$function (array $data): array

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

// Create the closure that adds 'a' to the end of an array.
$addA = Arrays\append('a');

// Called as a function.
var_dump($addA(['b', 'c'])); // ['b', 'c', 'a']

Curried

This can be called inline using currying.

// Adds `a` to the end of an array

 var_dump(Arrays\append('a')(['b', 'c'])); // ['b', 'c', 'a']

Details

Arrays Functions

Releated Array manipulation Functions