-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change
Milestone
Description
I would like to propose a new keyword "reflow".
This keyword acts as "return" only if the last value to return is not nil, otherwise it does nothing and execution of function goes on.
It can be very helpful to return values along with an error without having to write an if statement to check that the error is not nil every time.
It replaces a function like this:
func MyFunction() (data string, err error) {
if data, err = doSomething(); err != nil {
return data, err
}
...
doAnotherThing(data)
return data, nil
}
in a more concise way:
func MyFunction() (data string, err error) {
data, err = doSomething()
reflow data, err
...
doAnotherThing(data)
return data, nil
}
Practically, the reflow keyword returns from function only if the last argument is not nil.
JelteF, sebtzm, arthurdouillard, overcyn and xosmigcznic, virtuallynathan, davecheney, choleraehyq, marekk657 and 14 more
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change