/** * @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); }
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); }