use Widmogrod\Common;
use FunctionalPHP\FantasyLand;
use Widmogrod\Primitive\TypeMismatchError;
+use Widmogrod\Useful\PatternMatcher;
-class Just implements Maybe
+class Just implements Maybe, PatternMatcher
{
use Common\PointedTrait;
{
return $function($accumulator, $this->value);
}
+
+ /**
+ * @inheritdoc
+ */
+ public function patternMatched(callable $fn)
+ {
+ return $fn($this->value);
+ }
}
namespace Widmogrod\Monad\Maybe;
use FunctionalPHP\FantasyLand;
+use Widmogrod\Useful\PatternMatcher;
-class Nothing implements Maybe
+class Nothing implements Maybe, PatternMatcher
{
const of = 'Widmogrod\Monad\Maybe\Nothing::of';
{
return $accumulator;
}
+
+ /**
+ * @inheritdoc
+ */
+ public function patternMatched(callable $fn)
+ {
+ return $fn();
+ }
}