Created
May 16, 2017 14:06
-
-
Save njlr/d60ef2049e1d177b28ba01e10bc55044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This... | |
float sqrt(float x) { | |
if (x < 0) { | |
throw std::string("x should be >= 0"); | |
} | |
return computeSqrt(x); | |
} | |
// ... can be transformed into this... | |
Either<std::string, float> sqrt(float x) { | |
if (x < 0) { | |
return left("x should be >=0"); | |
} | |
return right(computeSqrt(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment