Beispiel #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.');
 }
Beispiel #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.');
 }
Beispiel #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.');
 }
Beispiel #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.');
 }
Beispiel #5
0
 public function testEvalState()
 {
     $this->assertEquals(State::of(2)->run(null), [2, null], 'Evaluates with a state.');
 }
Beispiel #6
0
 public function testApplicativeConstructor()
 {
     $this->assertEquals(State::of(2)->evalState(null), 2, 'Constructs an applicative.');
 }
Beispiel #7
0
 public function testRun()
 {
     $this->assertEquals(State::of(5)->run(2), [5, 2], 'Runs the computation.');
 }
Beispiel #8
0
 public function testExec()
 {
     $this->assertEquals(State::of(null)->run(2), [null, 2], 'Executes the computation.');
 }
Beispiel #9
0
 public function testChain()
 {
     $this->assertEquals(State::of(2)->chain(function () {
         return State::of(3);
     })->run('hello'), [3, 'hello'], 'Chains.');
 }