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 testAp() { $addTwo = Either::of(function ($x) { return $x + 2; }); $id = function ($x) { return $x; }; $a = Either::of(5); $b = new Left(4); $this->assertEquals($addTwo->ap($a)->either($id, $id), 7, 'Applies to a Right.'); $this->assertEquals($addTwo->ap($b)->either($id, $id), 4, 'Applies to a Left.'); }