public function fmap($callable) { if ($this instanceof Just) { return Maybe::unit($callable($this->value)); } else { return $this; } }
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()); }