コード例 #1
0
ファイル: MapTest.php プロジェクト: php-fp/php-fp-state
 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
ファイル: GetTest.php プロジェクト: php-fp/php-fp-state
 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
ファイル: PutTest.php プロジェクト: php-fp/php-fp-state
 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
ファイル: ModifyTest.php プロジェクト: php-fp/php-fp-state
 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
ファイル: EvalStateTest.php プロジェクト: php-fp/php-fp-state
 public function testEvalState()
 {
     $this->assertEquals(State::of(2)->run(null), [2, null], 'Evaluates with a state.');
 }
コード例 #6
0
ファイル: OfTest.php プロジェクト: php-fp/php-fp-state
 public function testApplicativeConstructor()
 {
     $this->assertEquals(State::of(2)->evalState(null), 2, 'Constructs an applicative.');
 }
コード例 #7
0
ファイル: RunTest.php プロジェクト: php-fp/php-fp-state
 public function testRun()
 {
     $this->assertEquals(State::of(5)->run(2), [5, 2], 'Runs the computation.');
 }
コード例 #8
0
ファイル: ExecTest.php プロジェクト: php-fp/php-fp-state
 public function testExec()
 {
     $this->assertEquals(State::of(null)->run(2), [null, 2], 'Executes the computation.');
 }
コード例 #9
0
ファイル: ChainTest.php プロジェクト: php-fp/php-fp-state
 public function testChain()
 {
     $this->assertEquals(State::of(2)->chain(function () {
         return State::of(3);
     })->run('hello'), [3, 'hello'], 'Chains.');
 }