Option::fromReturn( callable $callback, array $arguments = array(), mixed $noneValue = null )
Creates a lazy-option with the given callback.
Description
This is also a helper constructor for lazy-consuming existing APIs where the return value is not yet an option. By default, we treat null
as None case, and everything else as Some.
Parameters
- $callback
-
(callable) (Required) The callback to evaluate.
- $arguments
-
(array) (Optional)
Default value: array()
- $noneValue
-
(mixed) (Optional) The value which should be considered "None"; null by default.
Default value: null
Return
(PhpOptionOption)
Source
File: vendor/phpoption/phpoption/src/PhpOption/Option.php
public static function fromReturn($callback, array $arguments = array(), $noneValue = null)
{
return new LazyOption(function() use ($callback, $arguments, $noneValue) {
$return = call_user_func_array($callback, $arguments);
if ($return === $noneValue) {
return None::create();
}
return new Some($return);
});
}