示例#1
0
function fmap(...$args)
{
    $f = function (callable $f, $a) {
        return Loader::callInstanceMethod($a, 'fmap', $f, $a);
    };
    if (count($args) === 2) {
        return $f(...$args);
    } else {
        return f($f, ...$args);
    }
}
示例#2
0
function ap(...$args)
{
    $f = function ($f, $g) {
        return Loader::callInstanceMethod($f, 'ap', $f, $g);
    };
    if (count($args) === 2) {
        return $f(...$args);
    } else {
        return f($f, ...$args);
    }
}
示例#3
0
 public function cast($m)
 {
     if (is_object($m) || is_string($m) || is_array($m)) {
         $args = [];
         if (!$this->value instanceof Nul) {
             $args[] = $this->value;
         }
         $ret = Loader::callInstanceMethod($m, $this->op, ...$args);
         return $this->opsFold($ret);
     }
     throw new \Exception('Unsupported cast [' . gettype($m) . ']');
 }
示例#4
0
function bind(...$args)
{
    $f = function ($m, callable $f) {
        $ret = Loader::callInstanceMethod($m, 'bind', $m, $f);
        if ($ret instanceof Any) {
            $ret = $ret->cast($m);
        }
        return $ret;
    };
    if (count($args) === 2) {
        return $f(...$args);
    } else {
        return f($f, ...$args);
    }
}
示例#5
0
function mplus(...$args)
{
    $f = function ($m1, $m2) {
        if ($m1 instanceof Any && !$m2 instanceof Any) {
            $m1 = $m1->cast($m2);
        } else {
            if ($m2 instanceof Any && !$m1 instanceof Any) {
                $m2 = $m2->cast($m1);
            }
        }
        return Loader::callInstanceMethod($m1, 'mplus', $m1, $m2);
    };
    if (count($args) === 2) {
        return $f(...$args);
    } else {
        return f($f, ...$args);
    }
}