widmogrod/php-functional

View on GitHub
src/Primitive/Product.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types=1);

namespace Widmogrod\Primitive;

use FunctionalPHP\FantasyLand;

class Product extends Num implements
    FantasyLand\Monoid,
    FantasyLand\Pointed
{
    /**
     * @inheritdoc
     */
    public static function mempty()
    {
        return self::of(1);
    }

    /**
     * @inheritdoc
     */
    public function concat(FantasyLand\Semigroup $value): FantasyLand\Semigroup
    {
        if ($value instanceof self) {
            return self::of($this->extract() * $value->extract());
        }

        throw new TypeMismatchError($value, self::class);
    }
}