if/else expression. Works well with always() as the else branch for default values.
Creates a Closure that branches on a predicate — applies one transformation when the predicate is true, another when it's false.
/**
* @param callable(mixed):bool $condition
* @param callable(mixed):mixed $then
* @param callable(mixed):mixed $else
* @return Closure(mixed):mixed
*/
GeneralFunctions\ifElse(callable $condition, callable $then, callable $else): ClosureWhen GeneralFunctions\ifElse() 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.
$bucket = GeneralFunctions\ifElse(
fn($n) => $n >= 0,
GeneralFunctions\always('positive'),
GeneralFunctions\always('negative')
);
echo $bucket(42); // 'positive'
echo $bucket(-7); // 'negative'