public function testConstruct() { $IO = new IO(function () { return 2; }); $this->assertEquals($IO->unsafePerform(), 2, 'Constructs an IO.'); }
public function testChain() { $getLine = new IO(function () { return 'Hello, world!'; }); $putStrLn = function ($str) { return new IO(function () use($str) { return $str; }); }; return $this->assertEquals($getLine->chain($putStrLn)->unsafePerform(), 'Hello, world!', 'Chains correctly.'); }
public function testMap() { $mapper = function ($x) { return $x + 2; }; $this->assertEquals(IO::of(2)->map($mapper)->unsafePerform(), 4, 'Maps the inner value.'); }
public function testAp() { $add = function ($x) { return function ($y) use($x) { return $x + $y; }; }; $a = IO::of(2); $b = IO::of(4); $this->assertEquals(IO::of($add)->ap($a)->ap($b)->unsafePerform(), 6, 'Applies parameters.'); }
public function testUnsafePerform() { $this->assertEquals(IO::of(2)->unsafePerform(), 2, 'Forks the monad.'); }
public function testApplicativeConstructor() { $this->assertEquals(IO::of(2)->unsafePerform(), 2, 'Constructs an applicative.'); }