ILIAS  release_8 Revision v8.24
DeriveApplyToFromTransform.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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: Error.php:18
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:17
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
applyTo(Result $result)
@inheritDoc