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
Either: How to indicate success/failure from a void method? #853
Comments
This tells me that you are not thinking functionally. The functional style to always return something. That something can be a representation of nothing, which is also called I think you want the return type to be |
OK, thanks. I knew it had to have a simple answer 😀 |
Quick follow-up if you don't mind. The previous, not-very-functional incarnation of this method had a return type of
Now I have changed the method to return an I tried the following..
...but that gave a compiler error "cannot convert from 'void' to 'System.Action<LanguageExt.Unit>'" on the line that calls What should I do? Thanks again. |
Duh, just realised that it should be this...
Is that right? Thanks again. |
Yes, that looks correct to me. |
thanks |
Simple question. Suppose I have a method that does not return data, for example...
Now I want the return type to indicate if the operation succeeded. The obvious choice seems to be an
Either
, but that has two generic types, one usually used for the returned data, and one for the data. However, as I don't have any data to return, it seems pointless having a generic type that I won't use.I don't think
Try
would be the right thing, as that assumes a return type for the happy path, whereas I don't have one. I only want to return something (an error message) if the operation failed.Anyone able to advise? Thanks
The text was updated successfully, but these errors were encountered: