-
-
Notifications
You must be signed in to change notification settings - Fork 823
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
Delayed error checking #101
Comments
You use case is interesting. I wonder if it could be replaced by Must+Try: err, ok := lo.TryWithErrorValue(func() error {
complexStruct{
id: Must(doSimpleThing1()),
name: Must(doSimpleThing2()),
email: Must(doSimpleThing2()),
...
}
return nil
}) WDYT? |
@samber I wrote 3 different way to make |
Using this On the other side, Try+Must will halt the function and immediately return the error. I don't want to block this contrib, but I wonder if we could make it easier to use. |
I totally agree with you, and I think there are no way to make the function easier to use due to limitation of Go. |
I use this function personally. With this, you can save dozens of lines with
if err != nil
. Execute all simple logics (doSimpleThing
) first, and check the error later. The error will be the first occured error or nil.Example:
I think this function is appropriate for this package if there's a good name for it. Do you have a good idea?
The text was updated successfully, but these errors were encountered: