Exemple #1
0
 public function testConstruct()
 {
     $IO = new IO(function () {
         return 2;
     });
     $this->assertEquals($IO->unsafePerform(), 2, 'Constructs an IO.');
 }
Exemple #2
0
 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.');
 }
Exemple #3
0
 public function testMap()
 {
     $mapper = function ($x) {
         return $x + 2;
     };
     $this->assertEquals(IO::of(2)->map($mapper)->unsafePerform(), 4, 'Maps the inner value.');
 }
Exemple #4
0
 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.');
 }
Exemple #6
0
 public function testApplicativeConstructor()
 {
     $this->assertEquals(IO::of(2)->unsafePerform(), 2, 'Constructs an applicative.');
 }