Created
May 16, 2017 14:08
-
-
Save njlr/66428fa7937b3551ac2716b5e2b46fda 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
// And for the caller, the usage changes from this... | |
try { | |
float x = sqrt(-1); | |
std::cout << "sqrt(x) = " << x << std::endl; | |
} catch(std::string x) { | |
std::cout << "error occurred: " << x << std::endl; | |
} | |
// ... to this... | |
std::string msg = sqrt(-1) | |
.leftMap([](auto msg) { return "error occurred: " + msg; }) | |
.rightMap([](auto result) { return "sqrt(x) = " + to_string(result); }) | |
.join(); | |
std::cout << msg << std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment