On Wed, Jul 29, 2020 at 7:46 AM Kaveh Shahbazian <kaveh.shahbaz...@gmail.com> wrote: > > Go can already pass/pipe the result of a function, which returns multiple > values, to another function, which accepts the same values as arguments. A > similar mechanism can be used for handling errors, by passing/pipe them to a > special construct. > > Now, assume we have a function named funcCtx: > > func funcCtx() (res int, err error) { > // ... > } > > Having that, these does not look that ugly: > > func funcCtx() (res int, err error) { > res, return() = action() > // or > res, panic() = action() > } > > Those statements will have an effect, only if the returned value is not nil. > For performing some actions, before the actual return or panic: > > res, return({ log.Println(err) }) = action() > > There is this restriction, that the function that contains this block, > funcCtx, has to return named return values - for both handling the zero > values and having a one to one mapping between its return values and those of > action function. > > Also for having a name, err in this case, that makes it clear, which variable > we are talking about. > > In the proposal, it's not clear where the err variable comes from (what if > there are three return values?)
Thanks. This idea seems somewhat similar to https://golang.org/issue/27519. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXg1E6aNpcLu%2BFNSwg2GkLZQ0YLeKe2yvwUVuYyx9QVpg%40mail.gmail.com.