Creates a Closure that applies a transformation only when a predicate is true; otherwise returns the input unchanged.
/**
* @param callable(mixed):bool $condition
* @param callable(mixed):mixed $then
* @return Closure(mixed):mixed
*/
GeneralFunctions\ifThen(callable $condition, callable $then): ClosureWhen GeneralFunctions\ifThen() is called, it returns the following Closure which can be used like a regular function.
/**
* @param mixed $value
* @return mixed
*/
$function ($value)This can be used to create a simple closure which can be used as a regular function.
// Upper-case only strings; leave everything else alone.
$shoutStrings = GeneralFunctions\ifThen('is_string', 'strtoupper');
var_dump($shoutStrings('foo')); // 'FOO'
var_dump($shoutStrings(42)); // 42 (unchanged)