Here are my notes on how multiple returns work.
5 | func split(sum int) (x, y int) { |
14 | fmt.Println(split(17)) |
Returns prog.go:12: multiple-value split() in single-value context
(Check it out on the Go Playground)
5 | func split(sum int) (x, y int) { |
12 | resultsx, resultsy := split(17) |
15 | fmt.Println(split(17)) |
Returns:
(Check it out on the Go Playground)
If a function returns multiple things, you are required to give each of those things a name if you are going to save them to a variable. The exception (so far) is if you directly pass the function to another function that can handle that sort of thing.
If you don’t want to save one of the returns, you can assign it to _
, which basically says ‘I know there is going to be something here, throw it out immediately’.