Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error_or to round off functional interface #118

Open
operator-name opened this issue Sep 22, 2022 · 0 comments
Open

Add error_or to round off functional interface #118

operator-name opened this issue Sep 22, 2022 · 0 comments

Comments

@operator-name
Copy link

operator-name commented Sep 22, 2022

error_or would be the compliment to value_or

The motivation here is to flesh out the error handling path. When an error occurs it's likely that other expected functions may be called to cleanup. At the moment this would look like this:

auto delete_file = [](auto&& err){
    return do_delete()
       .and_then([err = srd::move(err ](auto&& _) { return tl::make_unexpected(err); }) // propogage initial error
       .error()
};

create_file()
   .and_then(write_file)
   .map_error(delete_file)
   .and_then(rename_file)

With error_or, delete_file could look like:

auto delete_file = [](auto&& err) {
    return do_delete()
       .error_or(err);
};

on_error is a more powerful or_else, it could conditionally turn an error into a value again. This would also be useful during error handling, perhaps as a "cleanup and try a different technique that might still fail" type function.

This is also suggested in the proposal: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2505r4.html

@operator-name operator-name changed the title Add error_or and on_error to round off functional interface Add error_or and on_error (naming?) to round off functional interface Sep 22, 2022
@operator-name operator-name changed the title Add error_or and on_error (naming?) to round off functional interface Add error_or to round off functional interface Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant