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