*/ final class Error extends Result { /** * @var E */ private $value; /** * Internal constructor for an error value. * * @param E $value * * @return void */ private function __construct($value) { $this->value = $value; } /** * Create a new error value. * * @template F * * @param F $value * * @return Result */ public static function create($value): Result { return new self($value); } /** * Get the success option value. * * @return Option */ public function success(): Option { return None::create(); } /** * Map over the success value. * * @template S * * @param callable(T):S $f * * @return Result */ public function map(callable $f): Result { return self::create($this->value); } /** * Flat map over the success value. * * @template S * @template F * * @param callable(T):Result $f * * @return Result */ public function flatMap(callable $f): Result { /* @var Result */ return self::create($this->value); } /** * Get the error option value. * * @return Option */ public function error(): Option { return Some::create($this->value); } /** * Map over the error value. * * @template F * * @param callable(E):F $f * * @return Result */ public function mapError(callable $f): Result { return self::create($f($this->value)); } }