'when' is called with the left value function when the monad isLeft is true
auto either = Either!(int, bool)(1); string result = "none"; either .when((int value) { result = "left"; }) .when((bool value) { result = "right"; }); result.should.equal("left");
it calls the 'when' with right value function when the monad isRight is true
auto either = Either!(int, bool)(true); string result = "none"; either .when((int value) { result = "left"; }) .when((bool value) { result = "right"; }); result.should.equal("right");
it does not call the 'when' function when the types don't match
auto either = Either!(int, bool)(true); string result = "none"; either .when((double value) { result = "double"; }) .when((string value) { result = "string"; }); result.should.equal("none");
it returns the binded value when the 'when' function returns
auto either = Either!(int, bool)(1); bool message; auto result = either .when((int value) { return true; }) .when((bool value) { message = value; }); result.isRight.should.equal(true); message.should.equal(true);
Match Left or Right values using types