Exemplo n.º 1
0
 public function testMap()
 {
     $addTwo = function ($x) {
         return $x + 2;
     };
     $id = function ($x) {
         return $x;
     };
     $a = new Right(5);
     $b = new Left(4);
     $this->assertEquals($a->map($addTwo)->either($id, $id), 7, 'Maps a Right.');
     $this->assertEquals($b->map($addTwo)->either($id, $id), 4, 'Maps a Left.');
 }
Exemplo n.º 2
0
 public function testChain()
 {
     $addTwo = function ($x) {
         return Either::of($x + 2);
     };
     $id = function ($x) {
         return $x;
     };
     $a = Either::of(5);
     $b = new Left(4);
     $this->assertEquals($a->chain($addTwo)->either($id, $id), 7, 'Chains a Right.');
     $this->assertEquals($b->chain($addTwo)->either($id, $id), 4, 'Chains a Left.');
 }
Exemplo n.º 3
0
 public function testEither()
 {
     $addOne = function ($x) {
         return $x + 1;
     };
     $takeOne = function ($x) {
         return $x - 1;
     };
     $a = new Right(2);
     $b = new Left(2);
     $this->assertEquals($a->either($addOne, $takeOne), 1, 'Eithers a Right.');
     $this->assertEquals($b->either($addOne, $takeOne), 3, 'Eithers a Left.');
 }
Exemplo n.º 4
0
 public function testBimap()
 {
     $addOne = function ($x) {
         return $x + 1;
     };
     $takeOne = function ($x) {
         return $x - 1;
     };
     $id = function ($x) {
         return $x;
     };
     $a = new Right(2);
     $b = new Left(2);
     $this->assertEquals($a->bimap($addOne, $takeOne)->either($id, $id), 1, 'Bimaps a Right.');
     $this->assertEquals($b->bimap($addOne, $takeOne)->either($id, $id), 3, 'Bimaps a Left.');
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  * @return Left
  */
 public static function ofLeft($value)
 {
     return Left::of($value);
 }