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