コード例 #1
0
ファイル: MonadZero.php プロジェクト: nishimura/laiz-monad
function guard(...$args)
{
    return f(function ($a) {
        if ($a) {
            return Func\Applicative\pure(new Func\Unit());
        } else {
            return Func\MonadZero\mzero();
        }
    }, ...$args);
}
コード例 #2
0
ファイル: ContextTest.php プロジェクト: nishimura/laiz-monad
 private function searchTree(callable $f, Tree $tree)
 {
     if ($tree instanceof EmptyTree) {
         return mzero();
     }
     if ($f($tree->value)) {
         return $this->searchTree($f, $tree->left)->mplus(ret($tree->value))->mplus($this->searchTree($f, $tree->right));
     } else {
         return $this->searchTree($f, $tree->left)->mplus($this->searchTree($f, $tree->right));
     }
 }
コード例 #3
0
ファイル: AnyTest.php プロジェクト: nishimura/laiz-monad
 public function testFromMaybe()
 {
     $this->assertEquals('a', fromMaybe('a', mzero()));
     $this->assertEquals(2, fromMaybe(2, mzero()));
 }