ILIAS  release_8 Revision v8.24
Result.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6
7namespace ILIAS\Data;
8
14interface Result
15{
19 public function isOK(): bool;
20
28 public function value();
29
33 public function isError(): bool;
34
41 public function error();
42
49 public function valueOr($default);
50
58 public function map(callable $f): Result;
59
70 public function then(callable $f): Result;
71
83 public function except(callable $f): Result;
84}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:15
then(callable $f)
Get a new result from the callable or do nothing if this is an error.
isError()
Get to know if the result is an error.
valueOr($default)
Get the encapsulated value or the supplied default if result is an error.
except(callable $f)
Feed the error into a callable and replace this with the result or do nothing if this is a value.
isOK()
Get to know if the result is ok.
map(callable $f)
Create a new result where the contained value is modified with $f.
value()
Get the encapsulated value.
error()
Get the encapsulated error.