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