ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DeriveApplyToFromTransform.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Refinery;
22
26use 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}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
then(callable $f)
Get a new result from the callable or do nothing if this is an error.
applyTo(Result $result)
@inheritDoc