Exemple #1
0
 public static function fmap(callable $f, $a)
 {
     assert($a instanceof Instance, 'Second argument must be Either');
     if ($a instanceof Instance\Left) {
         return $a;
     }
     return Right($f($a->value));
 }
Exemple #2
0
 public static function ap($mf, $a)
 {
     return f(function (Instance $mf, Instance $a) {
         if ($mf instanceof Instance\Left || $a instanceof Instance\Left) {
             return $fm;
         }
         $f = $mf->value;
         return Right($f($a->value));
     }, $mf, $a);
 }
Exemple #3
0
 /**
  * Converts Some to a Right, else it becomes a Left containing the return of $left
  * @param callable $left a function holder for some alternative value
  * @return Left|Right
  */
 public function toRight(callable $left)
 {
     return $this->isEmpty() ? Left(call_user_func($left)) : Right($this->get());
 }
 function testRight()
 {
     $this->assertEquals('df', Right("asdf", 2), 'Test1');
     $this->assertEquals('', Right("asdf", 0), 'Test2');
 }