GeneralFunctions\composeSafe()

higher-order composer variadic returns Closure pure
...(T → T | null) → (T → T | null)
At a glance — Null-safe composition. If your chain includes lookups or conversions that may fail to null, this variant guards every step without needing explicit checks.

Like compose() but halts the chain and returns null if any callable produces a null value. Prevents passing null into callables that can't handle it.

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

Returned Closure

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

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

Examples

Partial Application

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

$nameOfAdmin = GeneralFunctions\composeSafe(
  GeneralFunctions\getProperty('admin'),
  GeneralFunctions\getProperty('name')
);

echo $nameOfAdmin(['admin' => ['name' => 'Ada']]); // 'Ada'

var_dump($nameOfAdmin(['admin' => null])); // NULL (chain halted)

Details

General Functions

Releated Composition Functions