Arrays\arrayCompiler()

accumulator returns Closure pure
T[] → (T? → Closure | T[])
At a glance — Self-returning array builder. Each call with a value adds it and returns a fresh compiler; call with nothing (or null) to read the array out.

Creates a self-returning array accumulator. Each call with a value appends it and returns a fresh compiler; calling with no argument returns the accumulated array.

/**
  * @param mixed[] $inital Initial array contents.
  * @return Closure
  */
Arrays\arrayCompiler(array $inital = []): Closure

Examples

Partial Application

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

$compile = Arrays\arrayCompiler();

$compile = $compile('a');
$compile = $compile('b');
$compile = $compile('c');

var_dump($compile()); // ['a', 'b', 'c']

Curried

This can be called inline using currying.

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

Details

Arrays Functions

Releated Array compiler Functions