ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\Data\Result\Ok Class Reference

A result encapsulates a value or an error and simplifies the handling of those. More...

+ Inheritance diagram for ILIAS\Data\Result\Ok:
+ Collaboration diagram for ILIAS\Data\Result\Ok:

Public Member Functions

 __construct ($value)
 
 isOK ()
 Get to know if the result is ok. More...
 
 value ()
 Get the encapsulated value.
Returns
mixed
Exceptions
More...
 
 isError ()
 Get to know if the result is an error. More...
 
 error ()
 Get the encapsulated error.
Returns
|string
Exceptions
More...
 
 valueOr ($default)
 Get the encapsulated value or the supplied default if result is an error.
Parameters
mixed$default
Returns
mixed
More...
 
 map (callable $f)
 Create a new result where the contained value is modified with $f.Does nothing if !isOK.
Parameters
callable$fmixed -> mixed
More...
 
 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.
Parameters
callable$fmixed -> Result|null
Exceptions
More...
 
 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.
Parameters
callable$fstring| -> Result|null
Exceptions
More...
 

Protected Attributes

 $value
 

Detailed Description

A result encapsulates a value or an error and simplifies the handling of those.

Author
Stefan Hecken stefa.nosp@m.n.he.nosp@m.cken@.nosp@m.conc.nosp@m.epts-.nosp@m.and-.nosp@m.train.nosp@m.ing..nosp@m.de

Definition at line 30 of file Ok.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\Result\Ok::__construct (   $value)

Definition at line 37 of file Ok.php.

References ILIAS\Data\Result\Ok\$value, and ILIAS\Data\Result\Ok\value().

38  {
39  $this->value = $value;
40  }
value()
Get the encapsulated value.mixed
Definition: Ok.php:53
+ Here is the call graph for this function:

Member Function Documentation

◆ error()

ILIAS\Data\Result\Ok::error ( )

Get the encapsulated error.

Returns
|string
Exceptions

Implements ILIAS\Data\Result.

Definition at line 69 of file Ok.php.

70  {
71  throw new \LogicException("This is a OK result. No error message available");
72  }

◆ except()

ILIAS\Data\Result\Ok::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.

Parameters
callable$fstring| -> Result|null
Exceptions

Implements ILIAS\Data\Result.

Definition at line 114 of file Ok.php.

114  : Result
115  {
116  return $this;
117  }

◆ isError()

ILIAS\Data\Result\Ok::isError ( )

Get to know if the result is an error.

Implements ILIAS\Data\Result.

Definition at line 61 of file Ok.php.

61  : bool
62  {
63  return false;
64  }

◆ isOK()

ILIAS\Data\Result\Ok::isOK ( )

Get to know if the result is ok.

Implements ILIAS\Data\Result.

Definition at line 45 of file Ok.php.

45  : bool
46  {
47  return true;
48  }

◆ map()

ILIAS\Data\Result\Ok::map ( callable  $f)

Create a new result where the contained value is modified with $f.Does nothing if !isOK.

Parameters
callable$fmixed -> mixed

Implements ILIAS\Data\Result.

Definition at line 85 of file Ok.php.

References Vendor\Package\$f, ILIAS\Data\Result\Ok\$value, and ILIAS\Data\Result\Ok\value().

85  : Result
86  {
87  $clone = clone $this;
88  $value = $f($this->value);
89  $clone->value = $value;
90  return $clone;
91  }
value()
Get the encapsulated value.mixed
Definition: Ok.php:53
+ Here is the call graph for this function:

◆ then()

ILIAS\Data\Result\Ok::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.

Parameters
callable$fmixed -> Result|null
Exceptions

Implements ILIAS\Data\Result.

Definition at line 96 of file Ok.php.

References Vendor\Package\$f, null, and ILIAS\Data\Result\Ok\value().

96  : Result
97  {
98  $result = $f($this->value);
99 
100  if ($result === null) {
101  return $this;
102  }
103 
104  if (!$result instanceof Result) {
105  throw new \UnexpectedValueException("The returned type of callable is not an instance of interface Result");
106  }
107 
108  return $result;
109  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
value()
Get the encapsulated value.mixed
Definition: Ok.php:53
+ Here is the call graph for this function:

◆ value()

ILIAS\Data\Result\Ok::value ( )

Get the encapsulated value.

Returns
mixed
Exceptions

Implements ILIAS\Data\Result.

Definition at line 53 of file Ok.php.

References ILIAS\Data\Result\Ok\$value.

Referenced by ILIAS\Data\Result\Ok\__construct(), ILIAS\Data\Result\Ok\map(), and ILIAS\Data\Result\Ok\then().

54  {
55  return $this->value;
56  }
+ Here is the caller graph for this function:

◆ valueOr()

ILIAS\Data\Result\Ok::valueOr (   $default)

Get the encapsulated value or the supplied default if result is an error.

Parameters
mixed$default
Returns
mixed

Implements ILIAS\Data\Result.

Definition at line 77 of file Ok.php.

References ILIAS\Data\Result\Ok\$value.

78  {
79  return $this->value;
80  }

Field Documentation

◆ $value

ILIAS\Data\Result\Ok::$value
protected

The documentation for this class was generated from the following file: