GeneralFunctions\composeR()

higher-order composer variadic returns Closure pure
...(T → T) → (T → T)
At a glance — Same as compose but right-to-left. Useful when the natural reading order of your callables is the opposite of their execution order (e.g. mathematical function notation).

Like compose() but threads the value through callables right-to-left — the last callable is applied first.

/**
  * @param callable(mixed):mixed ...$callables
  * @return Closure(mixed):mixed
  */
GeneralFunctions\composeR(callable ...$callables): Closure

Returned Closure

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

/**
  * @param mixed $value
  * @return mixed
  */
$function ($value)

Examples

Partial Application

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

$shoutTrimmed = GeneralFunctions\composeR(
  'strtoupper',
  'trim'
);

// Equivalent to strtoupper(trim('  foo  '))
echo $shoutTrimmed('  foo  '); // 'FOO'

Details

General Functions

Releated Composition Functions