Skip to content

Instantly share code, notes, and snippets.

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