GeneralFunctions\pipe()

higher-order variadic returns value pure
(T, ...(T → T)) → T
At a glance — Direct call — not a Closure constructor. Use when you have a specific value you want to transform right now; use compose when you want a reusable Closure.

Immediately threads a value through a sequence of callables left-to-right and returns the final result. The imperative cousin of compose().

/**
  * @param mixed $value
  * @param callable(mixed):mixed ...$callables
  * @return mixed
  */
GeneralFunctions\pipe($value, callable ...$callables)

Examples

Partial Application

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

$slug = GeneralFunctions\pipe(
  '  Hello World  ',
  'trim',
  'strtolower',
  Strings\replaceWith(' ', '-')
);

echo $slug; // 'hello-world'

Details

General Functions

Releated Composition Functions