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.'); }
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.'); }
public function testApplicativeConstructor() { $this->assertEquals(Reader::of(2)->run(4), 2, 'Constructs an applicative.'); }
public function testMap() { $this->assertEquals(Reader::of(2)->map(function ($x) { return $x * 5; })->run(20), 10, 'Maps.'); }
public function testAp() { $this->assertEquals(Reader::of(function ($x) { return $x + 2; })->ap(Reader::of(10))->run(50), 12, 'Applies.'); }