예제 #1
0
 public function testRun()
 {
     $this->assertEquals(Reader::of(2)->chain(function ($x) {
         return Reader::ask()->map(function ($y) use($x) {
             return $x + $y;
         });
     })->run(20), 22, 'Runs.');
 }
예제 #2
0
 public function testAsk()
 {
     $this->assertEquals(Reader::of(2)->chain(function ($x) {
         return Reader::ask()->map(function ($y) use($x) {
             return $x + $y;
         });
     })->run(4), 6, 'Accesses environment.');
 }
예제 #3
0
 public function testApplicativeConstructor()
 {
     $this->assertEquals(Reader::of(2)->run(4), 2, 'Constructs an applicative.');
 }
예제 #4
0
 public function testMap()
 {
     $this->assertEquals(Reader::of(2)->map(function ($x) {
         return $x * 5;
     })->run(20), 10, 'Maps.');
 }
예제 #5
0
 public function testAp()
 {
     $this->assertEquals(Reader::of(function ($x) {
         return $x + 2;
     })->ap(Reader::of(10))->run(50), 12, 'Applies.');
 }