3 ms·
In your new hotness, I believe that handler is already implicit, so you can just leave it off. What I am still curious about, and can't see whether or not is p
by jerf 8y ago
In your new hotness, I believe that handler is already implicit, so you can just leave it off.
What I am still curious about, and can't see whether or not is possible from the current draft (possible I've just skimmed too hard) is whether printSum can become:
func printSum(a, b string) error {
fmt.Println("result:",
check strconv.Atoi(a) +
check strconv.Atoi(b))
return nil
}
Possibly with an addition paren around the check.
(I'm just using this as an example; in this case I probably would assign x & y on separate lines since in this case this saves no lines, but there are other cases where I've wanted to be able to call a function that has an error but avoid the 4-line dance to unpack it.)
- ianlancetaylor 8y agoYes, what you write should work with the current draft.
- jerf 8y agoCool. It isn't something I'd want to abuse, but there are places in my code where it would clean things up nicely, too.
- cyphar 8y agoIt can, and this is mentioned in the error chain design doc[1]. [1]: https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling.md https://go.googlesource.com/proposal/+/master/design/go2draf...
- webkike 8y agoThat should be possible because check is an expression