ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
A result encapsulates a value or an error and simplifies the handling of those. More...
Public Member Functions | |
isOK () | |
Get to know if the result is ok. More... | |
value () | |
Get the encapsulated value. More... | |
isError () | |
Get to know if the result is an error. More... | |
error () | |
Get the encapsulated error. More... | |
valueOr ($default) | |
Get the encapsulated value or the supplied default if result is an error. More... | |
map (callable $f) | |
Create a new result where the contained value is modified with $f. More... | |
then (callable $f) | |
Get a new result from the callable or do nothing if this is an error. More... | |
except (callable $f) | |
Feed the error into a callable and replace this with the result or do nothing if this is a value. More... | |
A result encapsulates a value or an error and simplifies the handling of those.
To be implemented as immutable object.
Definition at line 11 of file Result.php.
ILIAS\Data\Result::error | ( | ) |
Get the encapsulated error.
LogicException | if isOK |
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
ILIAS\Data\Result::except | ( | callable | $f | ) |
Feed the error into a callable and replace this with the result or do nothing if this is a value.
If null is returned from $f, the error in the result is not touched.
Does nothing if !isError.
callable | $f | string| -> Result|null |
UnexpectedValueException | If callable returns no instance of Result |
Implemented in ILIAS\Data\Result\Ok, and ILIAS\Data\Result\Error.
ILIAS\Data\Result::isError | ( | ) |
Get to know if the result is an error.
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
Referenced by ILIAS\Validation\Constraints\Custom\restrict().
ILIAS\Data\Result::isOK | ( | ) |
Get to know if the result is ok.
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
ILIAS\Data\Result::map | ( | callable | $f | ) |
Create a new result where the contained value is modified with $f.
Does nothing if !isOK.
callable | $f | mixed -> mixed |
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
ILIAS\Data\Result::then | ( | callable | $f | ) |
Get a new result from the callable or do nothing if this is an error.
If null is returned from $f, the result is not touched.
Does nothing if !isOK. This is monadic bind.
callable | $f | mixed -> Result|null |
UnexpectedValueException | If callable returns no instance of Result |
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
ILIAS\Data\Result::value | ( | ) |
Get the encapsulated value.
Exception | if !isOK, will either throw the contained exception or a NotOKException if a string is contained as error. |
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.
Referenced by ILIAS\Validation\Constraints\Custom\restrict().
ILIAS\Data\Result::valueOr | ( | $default | ) |
Get the encapsulated value or the supplied default if result is an error.
default |
Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.