composeSafe's null-only check — e.g. "every step must still be a string".
Like compose() but guards each intermediate value with a validator callable. If the validator fails on a value, the chain aborts and returns null.
/**
* @param callable(mixed):bool $validator
* @param callable(mixed):mixed ...$callables
* @return Closure(mixed):mixed
*/
GeneralFunctions\composeTypeSafe(callable $validator, callable ...$callables): ClosureWhen GeneralFunctions\composeTypeSafe() is called, it returns the following Closure which can be used like a regular function.
/**
* @param mixed $value
* @return mixed|null
*/
$function ($value)This can be used to create a simple closure which can be used as a regular function.
$stringPipeline = GeneralFunctions\composeTypeSafe(
'is_string',
'trim',
'strtolower',
Strings\replaceWith(' ', '-')
);
echo $stringPipeline(' Hello World '); // 'hello-world'
var_dump($stringPipeline(42)); // NULL — 42 is not a string, chain halted