コード例 #1
0
ファイル: Maybe.php プロジェクト: yshnb/php-monadic
 public function fmap($callable)
 {
     if ($this instanceof Just) {
         return Maybe::unit($callable($this->value));
     } else {
         return $this;
     }
 }
コード例 #2
0
ファイル: MaybeTest.php プロジェクト: yshnb/php-monadic
 public function testFmap()
 {
     $maybe = Maybe::unit(1)->fmap(function ($val) {
         return null;
     })->fmap(function ($val) {
         $this->fail("this method must not be executed.");
         return null;
     });
     $this->assertInstanceOf("Monadic\\Type\\Maybe\\Nothing", $maybe);
     $this->assertNull($maybe->get());
 }