Вход Регистрация
Файл: vendor/graham-campbell/result-type/src/Success.php
Строк: 52
<?php

declare(strict_types=1);

/*
 * This file is part of Result Type.
 *
 * (c) Graham Campbell <hello@gjcampbell.co.uk>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GrahamCampbellResultType;

use 
PhpOptionNone;
use 
PhpOptionSome;

/**
 * @template T
 * @template E
 * @extends GrahamCampbellResultTypeResult<T,E>
 */
final class Success extends Result
{
    
/**
     * @var T
     */
    
private $value;

    
/**
     * Internal constructor for a success value.
     *
     * @param T $value
     *
     * @return void
     */
    
private function __construct($value)
    {
        
$this->value $value;
    }

    
/**
     * Create a new error value.
     *
     * @template S
     *
     * @param S $value
     *
     * @return GrahamCampbellResultTypeResult<S,E>
     */
    
public static function create($value)
    {
        return new 
self($value);
    }

    
/**
     * Get the success option value.
     *
     * @return PhpOptionOption<T>
     */
    
public function success()
    {
        return 
Some::create($this->value);
    }

    
/**
     * Map over the success value.
     *
     * @template S
     *
     * @param callable(T):S $f
     *
     * @return GrahamCampbellResultTypeResult<S,E>
     */
    
public function map(callable $f)
    {
        return 
self::create($f($this->value));
    }

    
/**
     * Flat map over the success value.
     *
     * @template S
     * @template F
     *
     * @param callable(T):GrahamCampbellResultTypeResult<S,F> $f
     *
     * @return GrahamCampbellResultTypeResult<S,F>
     */
    
public function flatMap(callable $f)
    {
        return 
$f($this->value);
    }

    
/**
     * Get the error option value.
     *
     * @return PhpOptionOption<E>
     */
    
public function error()
    {
        return 
None::create();
    }

    
/**
     * Map over the error value.
     *
     * @template F
     *
     * @param callable(E):F $f
     *
     * @return GrahamCampbellResultTypeResult<T,F>
     */
    
public function mapError(callable $f)
    {
        return 
self::create($this->value);
    }
}
Онлайн: 2
Реклама