ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DeriveApplyToFromTransform.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Refinery;
22 
26 use Exception;
27 
29 {
33  abstract public function transform($from);
34 
38  public function applyTo(Result $result): Result
39  {
40  return $result->then(function ($value): Result {
41  try {
42  return new Ok($this->transform($value));
43  } catch (Exception $exception) {
44  return new Error($exception);
45  }
46  });
47  }
48 }
then(callable $f)
Get a new result from the callable or do nothing if this is an error.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:30