Arrays\prepend()

transformer lazy accepts iterable returns Closure pure
T → (Iterable → Iterable)
At a glance — Bind a value to put at the front; the returned Closure yields it first, then the source lazily.

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

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

Returned Closure

When Arrays\prepend() 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 start of an array.
$addA = Arrays\prepend('a');

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

Curried

This can be called inline using currying.

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

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

Details

Arrays Functions

Releated Array manipulation Functions