예제 #1
0
파일: Maybe.php 프로젝트: bugadani/monad
 /**
  * @param $value
  * @return Monad
  */
 public static function unit($value)
 {
     if ($value instanceof Maybe) {
         return $value;
     }
     if ($value === null) {
         return Nothing::unit();
     }
     return new Just($value);
 }
예제 #2
0
 public function testMaybe()
 {
     $result = Just::unit(1)->bind(function ($value) {
         return null;
     })->bind(function ($value) {
         $this->fail();
         return 3;
     });
     $this->assertInstanceOf('Monad\\Nothing', $result);
     $result = Just::unit(Nothing::unit());
     $this->assertInstanceOf('Monad\\Nothing', $result);
 }