Skip to content

Instantly share code, notes, and snippets.

@njlr
Created May 16, 2017 14:06
Show Gist options
  • Save njlr/d60ef2049e1d177b28ba01e10bc55044 to your computer and use it in GitHub Desktop.
Save njlr/d60ef2049e1d177b28ba01e10bc55044 to your computer and use it in GitHub Desktop.
// 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