Ejemplo n.º 1
0
 public function testMap()
 {
     $inc = function ($x) {
         return $x + 1;
     };
     $this->assertEquals(State::of($inc)->ap(State::of(1))->run(null), [2, null], 'Aps.');
 }
Ejemplo n.º 2
0
 public function testGet()
 {
     $this->assertEquals(State::of(2)->chain(function ($x) {
         return State::get()->map(function ($y) use($x) {
             return $x + $y;
         });
     })->evalState(3), 5, 'Accesses state.');
 }
Ejemplo n.º 3
0
 public function testModify()
 {
     $this->assertEquals(State::of(2)->chain(function ($x) {
         return State::put(55)->map(function () use($x) {
             return $x;
         });
     })->run(5), [2, 55], 'Mutates state.');
 }
Ejemplo n.º 4
0
 public function testModify()
 {
     $this->assertEquals(State::of(2)->chain(function ($x) {
         $add = function ($x) {
             return $x + 1;
         };
         return State::modify($add)->map(function () use($x) {
             return $x;
         });
     })->run(10), [2, 11], 'Updates state.');
 }
Ejemplo n.º 5
0
 public function testEvalState()
 {
     $this->assertEquals(State::of(2)->run(null), [2, null], 'Evaluates with a state.');
 }
Ejemplo n.º 6
0
 public function testApplicativeConstructor()
 {
     $this->assertEquals(State::of(2)->evalState(null), 2, 'Constructs an applicative.');
 }
Ejemplo n.º 7
0
 public function testRun()
 {
     $this->assertEquals(State::of(5)->run(2), [5, 2], 'Runs the computation.');
 }
Ejemplo n.º 8
0
 public function testExec()
 {
     $this->assertEquals(State::of(null)->run(2), [null, 2], 'Executes the computation.');
 }
Ejemplo n.º 9
0
 public function testChain()
 {
     $this->assertEquals(State::of(2)->chain(function () {
         return State::of(3);
     })->run('hello'), [3, 'hello'], 'Chains.');
 }