Closed
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.