<U>Wrap a callable into one that transforms its result into an Option.
It will be a Some option containing the result if it is different from $noneValue (default null),
or, when $isSome is given, if $isSome($result) returns true ($noneValue and $isSome cannot be used together).
Successful execution:
self::assertEq(Option\ify(strtolower(...))("FRUITS"), Option\some("fruits"));
Conversion of null to Option\None:
self::assertEq(Option\ify(fn() => null)(), Option\none());
Option-ify strpos():
$strpos = Option\ify(strpos(...), isSome: is_int(...));
self::assertEq($strpos("fruits", "u"), Option\some(2));
self::assertEq($strpos("fruits", "z"), Option\none());
| Parameters | |||
|---|---|---|---|
callable(mixed...): U
|
$callback |
# | |
mixed
|
$noneValue = null |
# | |
bool
|
$strict = true |
# | |
(callable(U): bool)|null
|
$isSome = null |
# | |
| Returns | |
|---|---|
($isSome is null ? Closure(mixed...): Option<U> : ($noneValue is null ? Closure(mixed...): Option<U> : never))
|
|
| Throws | |
|---|---|
InvalidArgumentException |
if both |