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 "monadic" operations to result #94

Open
pdimov opened this issue Sep 30, 2022 · 5 comments
Open

Add "monadic" operations to result #94

pdimov opened this issue Sep 30, 2022 · 5 comments

Comments

@pdimov
Copy link
Member

pdimov commented Sep 30, 2022

r & f -> r? f(*r): r.error()
r | x -> r? r: x
r | f -> r? r: f()

https://godbolt.org/z/YWKKbq859

@pdimov
Copy link
Member Author

pdimov commented Mar 25, 2023

More like r | x -> r? *r: x, and similarly r | f -> r? *r: f().

@pdimov
Copy link
Member Author

pdimov commented Mar 25, 2023

r &= f; -> if( r ) r = f(*r);
r |= x; -> if( !r ) r = x;
r |= f; -> if( !r ) r = f();

@pdimov
Copy link
Member Author

pdimov commented Oct 31, 2023

Implemented on develop (without |= which is deemed unnecessary.)

In the future, maybe consider error-transforming variants of |, as in

r | f -> r? *r: f( r.error() )

@pdimov
Copy link
Member Author

pdimov commented Jan 31, 2024

r |= x should probably be provided for consistency, always with the effective semantics of r = r | x.

It only makes sense for r |= f; where f returns result, but it's probably less surprising to just support all the cases.

@pdimov
Copy link
Member Author

pdimov commented Feb 2, 2024

r |= x implemented on develop.

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