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.'); }
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.'); }
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.'); }
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.'); }
/** * @inheritdoc * @return Left */ public static function ofLeft($value) { return Left::of($value); }